I am trying to query an Oracle database using SQLPlus and save the result as CSV file. I only want the data, not the formatting provided by SQLPlus options such as numwidth
, linesize
and pagesize
etc.
I do not want to do extra processing using bash or awk to remove the presentation formatting, nor do I want to do complicated query like SELECT field1 || ',' || field2
etc
Currently I am trying to use the approach published here, but I am still not clear on how to avoid the presentation noise when saving to CSV.
https://chartio.com/resources/tutorials/how-to-write-to-a-csv-file-using-oracle-sql-plus/
set colsep ,
set headsep off
set pagesize 0
set trimspool on
set linesize 2
set numwidth 5
spool books.csv
SELECT
title,
primary_author
FROM
books;
spool off
This was StackOverflow questions and answers 8 years ago, but I am hoping better approaches are available now.
How do I spool to a CSV formatted file using SQLPLUS?
Thanks.