Chandru
Chandru

Reputation: 33

To execute multiple SQL files in single unix shell script

I have a SQL filequery.sql running thorugh a unix shell script and it directs an ouput to another SQL file called as result.sql

First file will give the sample output of below which will be written in the result.sql,

drop * from table1;
drop * from table 2;
drop * from table 3;  etc.. 

I need to execute both query.sql and result.sql in a single shell script and this should create a output file called as output.txt. How can I achieve this?

Upvotes: 0

Views: 14413

Answers (1)

Ed Gibbs
Ed Gibbs

Reputation: 26343

Something on this idea should work:

sqlplus -s username/password@servername << EOF
@query.sql
spool output.txt
@result.sql
spool off
EOF

Upvotes: 1

Related Questions