Retrieve data and redirect to a file

How to write a shell script to retrieve datas from database after that this database are redirect to a excell sheet and then i got a mail that gives details about the database with the column name and data..

I m using oracle 9i...

Thanks,
Anup Das

Get your data by calling appropriate SQL queries like SELECT etc. maybe via SQLPLUS and redirect it to someoutput file. As output delimeter you might want to choose something appropriate, maybe a semicolon, depending to your data so that it can be imported as let's say .csv file.
How to check for return codes of commands and how to send a notify mail is covered in plenty posts in this forum.

Connect to Oracle

Run the select and store the output in a variable or file.

Email the file - uuencode file file.csv | mail mail.com