SQL*Plus is primarily a command tool and a rudimentary report tool. It wasn't designed for robust programmatic data feeds, but it can be adapted to produce them with a bit of effort.
In your case, since line breaks also mess up line-based Unix tools that you might be piping file data through for cleansing, it's useful to get them out of your data at the source and keep them out until it reaches it's final destination.
To do this, replace any special characters that mess up SQL*Plus output with characters it won't do anything with, but which cannot occur in your data. Device control characters are used by virtually nothing so are good candidates:
SELECT TRANSLATE(mytext,CHR(10)||',',CHR(19)||CHR(20))
FROM table
Then on the consuming end, wherever that is, reverse the translation. You can use tr
or sed
in Unix, or if it's another Oracle database:
TRANSLATE(mytext,CHR(19)||CHR(20),CHR(10)||',')
You can use nested REPLACE
s as well, and any other character you are sure won't occur in your data.
Of course, also make sure you set linesize
, long
, longchunksize
, pagesize
, header
, etc.. and the -S
flag to appropriate values to get clean output.