I need to spool the output of tables from db to CSV file. I checked and referred to How do I spool to a CSV formatted file using SQLPLUS?
But it's not working successfully. What I am getting is only the first 3 columns being separated by ,
and not the remaining. Others are getting separated by newline.
EDIT : Schema Details of Table being Spooled.
WWID VARCHAR2 (5 Byte)
TIMELOG_DATE DATE
TOTAL_HOURS NUMBER (10,2)
ACTIVITY VARCHAR2 (100 Byte)
SUBACTIVITY VARCHAR2 (100 Byte)
REF_PROJECT_ID VARCHAR2 (30 Byte)
REF_PROJECT_DESC VARCHAR2 (250 Byte)
WORK_REQUEST_ID VARCHAR2 (30 Byte)
EMP_COMMENTS VARCHAR2 (100 Byte)
APPROVER_COMMENTS VARCHAR2 (100 Byte)
Script:
echo "\n>>> ******Data Processing Started at `date '+%d-%m-%Y %T %Z'`******" >>${LOGFILE}
sqlplus $fims_user/$fims_pwd << EOF
set serveroutput on;
set colsep , ;-- separate columns with a comma
set pagesize 0 ;-- No header rows
set trimspool on ;-- remove trailing blanks
set headsep off ;-- this may be useful...depends on your headings.
spool /home/fimsctl/datafiles/outbound/timelog/timelog_file_`date +%y%m%d`.csv
select * from FIMS_OWNER.TIMELOG_EXTRACT_OUTBOUND_T;
commit;
spool off
exit
EOF
echo "\n>>> ******Data Load Completed at `date '+%d-%m-%Y %T %Z'`******" >>${LOGFILE}
echo "End of the script">> ${LOGFILE}
And Output in CSV i am getting is:
SQL> select * from FIMS_OWNER.TIMELOG_EXTRACT_OUTBOUND_T;
iv315,29-DEC-14, 8
DUMMY
REF01
New Ref Project of type CPRM
66
NA
iv315,30-DEC-14, 8
DUMMY
REF01
New Ref Project of type CPRM
66
NA
iv315,31-DEC-14, 8
DUMMY
REF01
New Ref Project of type CPRM
66
NA
That is values are then separated by newline(when seen in wordpad)
Thanks