Calling SQL script from ksh job and send mail on some error.

Hi,
I am trying to call sql script from ksh job with parameters.The parameters passed from ksh job will be used in SELECT query in sql file to SPOOL the data in extract file.My questions are:

1) How to call a sql script from ksh job with parameters?
2) How to use the parameter in sql file to extract data from oracle tables to create txt file?
3)How to provide name to the extract file with current date format?e.g, EXTRACT_<YYYYMMDDhhmm>.txt in sql file?
4)How to check whether the called sql script with SPOOL action is successfully completed or not in ksh job?
5)How to send mail to support group on unsuccessful completion of sql performed from ksh job?

Can anyone give me some examples (Sample code) with proper syntax and details which will help me understand this concept?

Thanks in advance.

Regards,
Anil

Hi Anil
Check these examples here to get a fair idea on how to use sql inside shell

Guru.