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

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 11-04-2009
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
# 2  
Old 11-05-2009
after your 'set linesize' line add
Code:
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
# 3  
Old 11-09-2009
The ouput expecting is

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

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Run sql query in shell script and output data save as delimited text Jaganjag Shell Programming and Scripting 8 03-26-2017 12:26 PM
Read input file and used it to SQL query znesotomayor Shell Programming and Scripting 7 09-07-2015 11:10 AM
Shell scripting unable to send the sql query data in table in body of email Sharanakumar Shell Programming and Scripting 9 09-26-2014 10:50 AM
How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX? 24ajay Shell Programming and Scripting 1 03-14-2014 04:30 AM
SQL query in UNIX script - output in flat file juzz4fun Shell Programming and Scripting 13 05-31-2013 06:03 PM
Run SQL thru shell script: how to get a new line when run sql query? Kapom Shell Programming and Scripting 2 06-18-2012 11:30 AM
Need help to run sql query from a script..which takes input from a file rkrish Shell Programming and Scripting 1 09-20-2011 07:46 AM
How can I create a CSV file from PL/Sql in UNIX? Atrap Shell Programming and Scripting 2 10-06-2010 04:00 AM
executing SQL query using unix shell script nathanvaithi UNIX for Dummies Questions & Answers 3 12-04-2009 10:50 PM
how to use data in unix text file as input to an sql query from shell rdhanek Shell Programming and Scripting 7 07-02-2009 05:51 AM
How do I use SQL to query based off file data? whoknows UNIX for Dummies Questions & Answers 4 06-30-2009 11:02 AM
Execute PL/SQL function from Unix script (.sql file) reptile UNIX for Dummies Questions & Answers 1 05-14-2009 08:40 AM
TO execute .sql 2005 query file in shell script n2ekhil Shell Programming and Scripting 0 04-01-2009 06:14 AM
sql query results in unix shell script skyineyes UNIX for Dummies Questions & Answers 1 06-20-2007 11:56 AM
unloading sql query to file Link_02 Shell Programming and Scripting 2 02-23-2002 08:02 PM