SQL commands in a shell scripting

Hi,

I need to write a shell script file that does
1)Connects to DB using SQL plus
2)Do some SQL query like select * from....
3)Based on the output that I got from the sql query I will have to write a if else loop.

Plz let me know how to write the shell scripting for this.

Thanks for understanding.

i=`(
sqlplus -S clocapp/clocappstg@CLOC2ARCH010 <<ENDOFSQL
select max(dq_time) from amq_txn_ex;
ENDOFSQL
)
`
echo $i

This is working fine...

Sorry for this thread....