Need help in script

I am trying to write shell script that will pull output from sql db and store it in file in UNIX.
script:-

#echo $conn
sqlplus -l $conn << EOF
select name from employee where id = $1;
/
exit
EOF

i want to run the script in a way that i will pass id as parameter as well as output shoudl be stored in a file whic will also be passed as parameter.
Like below
if i want name of employee with id = 1 and want to store the output in out.txt, i want to run it like below:-

ksh script 1 out.txt

.

how can i achecive that

Where are you stuck? You could tell sqlplus to spool to $2 , or redirect the entire script's output like

ksh script 1 > out.txt

the thing is when i do like you said it gives output like

name
--------
ajay

i want the output file to have only ajay

Can't you switch the headers off?

You need to add a statement to your SQL to turn off the column headings:-

SET HEADING OFF

You can also call sqlplus with a -s or -S flag to reduce the information displayed during the connection.

I hope that this helps,
Robin

thanks,
it is generating the desired result in file.
Though there is one issue.
output shown in file is like:

more out.txt

ajay

there are blank spaces which should not be there

---------- Post updated at 08:15 AM ---------- Previous update was at 07:25 AM ----------

target acheived.

thanks for help