Post date: Aug 29, 2014 8:23:15 AM
I want to get the flat comma-separated file from terminal that runs SQLPlus. Here is how I manage to do it.
further resources:
sqlplus <user_id>_ro@<db_name>
SQL> set colsep , -- separate columns with a comma
SQL> set trimspool on -- remove trailing blanks
SQL> set pagesize 0 -- No header rows
SQL> set echo off
SQL> set feedback off
SQL> set headsep off -- this may or may not be useful...depends on your headings.
SQL> set linesize X -- X should be the sum of the column widths
SQL> set numw X -- X should be the length you want for numbers (avoid scientific notation on IDs)
SQL> spool '/tmp/kittipat_out_data.dat';
SQL> spool off;
sed 's/ \+//g' /tmp/kittipat_out_data.dat > /tmp/kittipat_out_data_clean.dat