Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL query syntax with replace and concatenate

Posted on 2012-03-27
4
Medium Priority
?
425 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
  • 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 78

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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to recover a database from a user managed backup
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

824 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