oracle - Header formatting while spooling a csv file in sqlplus -


i required spool csv table in oracle, using sqlplus. following format required:

"host_site_tx_id","site_id","sitetx_tx_id","sitetx_help_id" "664436565","16","2195301","0" "664700792","52","1099970","0" 

following relevant piece of shell script wrote:

sqlplus -s $sql_user/$sql_password@$sid << eof >> /dev/null     set feedback off     set term off     set linesize 1500     set pagesize 11000   --set colsep ,   --set colsep '","'     set trimspool on     set underline off     set heading on   --set headsep $     set newpage none       spool "$folder$filename$ext"     select '"'||pcl_carrier_name||'","'||sitetx_equip_id||'","'||sitetx_site_stat||'","'||sitetx_create_date||'","'||advtx_veh_wt||'"'     cvo_admin.missing_host_site_tx_ids;     spool off 

(i have used commented statements in, signify things tried couldn't work)

the output receive is:

'"'||pcl_carrier_name||'","'||sitetx_equip_id||'","'||sitetx_site_stat||'","'||sitetx_create_date||'","'||advtx_veh_wt||'"' "transport inc","113","00000000","25-jan-13 10.17.51 am","" "transport inc","1905","00000000","25-jan-13 05.06.44 pm","0" 

which shows header messed - literally printing whole string should have been interpreted sql statement, case data displayed.

options considering:

1) using colsep

set colsep '","' spool select * table spool off 

this introduces other problems data having leading , trailing spaces, first , last values in files not enclosed quotes

    host_site_tx_id","   site_id"     "             12345","      16"     "             12345","      21 

i concluded method gives me more heartburn 1 described earlier.

2) getting file , use regex modify header.

3) leaving header altogether , manually adding header string @ beginning of file, using script

option 2 more doable, still interested in asking, if there might better way format header somehow, comes in regular csv, (comma delimited, double quote bounded) format.

i looking less hard coding possible - table exporting has around 40 columns , running script around 4 million records - breaking them in batch of around 10k each. appreciate suggestions, totally different approach - programmer in learning.

one easy way have csv 1 header do

set embedded on set pagesize 0 set colsep '|' set echo off set feedback off set linesize 1000 set trimspool on set headsep off 

the embedded hidden option important have 1 header


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -