Solved

SQL query syntax with replace and concatenate

Posted on 2012-03-27
4
406 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 300 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 200 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 300 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

734 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