How to use sql data file in unix csv file as input to an sql query from shell

Hi ,

I used the below script to get the sql data into csv file using unix scripting.

I m getting the output into an output file but the output file is not displayed in a separe columns .

#!/bin/ksh
export FILE_PATH=/maav/home/xyz/abc/

rm $FILE_PATH/sample.csv
sqlplus -s pqr/Hello123 << EOF
spool on
set linesize 60
spool $FILE_PATH/CC_successful.csv
set head off
set pagesize 9999

select ename,eid,edate from emp where trunc(edate) = trunc(to_Date(sysdate))

EXIT
EOF

print "CC successful Orders" > $FILE_PATH/Dash.csv
cat $FILE_PATH/CC_successful.csv >> $FILE_PATH/Dash.csv
print "*************************" >> $FILE_PATH/Dash.csv

cd $FILE_PATH/
uuencode Dash.csv Dash.csv| mail -s "Dash for `date +%C%y%m%d` " pnareshnaidu@gmail.com"

Can some one please suggest me where i need to make changes in the above script

after your 'set linesize' line add

set colsepchar ','

something like that should work. your column separator is probably defaulting to tab or fixed width.

check out Oracle Commands for more info

After running the below sql query

select ename,eid,edate from emp where trunc(edate) = trunc(to_Date(sysdate))

output is

Ename Eid Edate
-----------------
xyz 987 8-11-2009
abc 453 8-11-2009

Expecting output is

Ename Eid Edate
-----------------
xyz 0987 08-11-2009
abc 0453 08-11-2009

Where 0(zero) was missing in the column Eid and Edate after export the results to csv file.

Please suggest me