Wednesday, January 7, 2009

Embedding SQL into Unix Script

Embedding of SQL query in Unix Script -


The automation usability of the Unix Scripting can be enhanced with embedding the SQL queries into a Unix script file.
It can be achieved as mentioned in the below examples -

1.
isql -S -U -P << EOF

EOF

Use isql command with the aforesaid options.
<< EOF says, do the execution of the embedded sql after this command line till word "EOF" is encountered.

The output would be displayed on command prompt only.


2. isql -S -U -P << EOF >analytics_result.txt

EOF


Same as above with one addition , the output can bbe redirected to a file with indirection ">". Here the output file is "analytics_result.txt"


3.
isql -S -U -P -i analytics_query.sql << EOF
EOF


In case of big queries or multiple query execution, all sql stuffs could be packaged into a sql file and the file path could be mentioned with the option "-i".


Scope -

This automation could be used for database functionalities and running database queries as a scheduled job.




Avaneesh
07-01-2009