Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL query syntax with replace and concatenate

Posted on 2012-03-27
4
Medium Priority
?
420 Views
Last Modified: 2012-03-27
Looking for help with query that spools data to ASCII file from table (tab1) with several  columns that have CR-s. If data doesn't have CR-s the following works:

spool tab1_data.out
select col1|| '|' ||
col2 || '|' ||
col3 || '|' ||
col4 || '|' ||
col5 || '|' ||
col6 from tab1 ;
spool off

However for two columns have to use

select replace (col3CHR(10),CHR(32))
select replace (col4CHR(10),CHR(32))

to replace CR with 'space'. - How to combine 'replace' functions and select-concatenate command?

Thank you Experts!
Regards
0
Comment
Question by:sevior
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 1200 total points
ID: 37772820
select col1|| '|' ||
col2 || '|' ||
replace (col3CHR(10),CHR(32))|| '|' ||
replace (col4CHR(10),CHR(32))|| '|' ||
col5 || '|' ||
col6 from tab1 ;
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 800 total points
ID: 37772823
Just use the function?


select col1|| '|' ||
col2 || '|' ||
replace (col3, CHR(10),CHR(32))|| '|' ||
replace (col4, CHR(10),CHR(32))|| '|' ||
col5 || '|' ||
col6 from tab1 ;
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 1200 total points
ID: 37772827
another option (if appropriate i.e. none of the other fields have new-lines in them)

simply execute the replace on the entire concatenation

select replace(col1|| '|' ||
col2 || '|' ||
col3 || '|' ||
col4 || '|' ||
col5 || '|' ||
col6,chr(10),chr(32)) from tab1 ;
0
 

Author Closing Comment

by:sevior
ID: 37772991
Thank you!<br />That worked well.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question