Skip to Main Content
  • Questions
  • Set CRLF or LF character as a new line character in SQL Plus

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Roman.

Asked: May 12, 2020 - 2:09 pm UTC

Last updated: May 14, 2020 - 5:15 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

Hi!

My goal is to extract data in a CSV-format. I do it like this:
set term off
set trimspool on
set head off
set feed off

spool output.csv
select level || ';some_val;'||to_char(sysdate, 'DD.MM.YYYY') line
from dual
connect by level <= 5;
spool off
exit


Everything is cool but SQL Plus sets CRLF as a line separator (as I'm on Windows). But my exported file will be handled later in *nix.
So the question is how can one set new line character in SQL Plus? Is it possible?
If not then how can I achieve this?

and Connor said...

I don't think sqlplus has a native way of doing this.

Once you have spooled your file, you can use utilities such as dos2unix or unix2dos to adjust the line feeds for your target environment. These are typically natively available on unix, and its easy to find Windows versions of these as well.



Is this answer out of date? If it is, please let us know via a Comment