I have n .sql files for example 1.sql, 2.sl, 3.sql.... n.sql in a folder named sql_scripts. I want to execute all those files using a single shell script. Whats the easiest and the most preferred way to do so?
3 Answers
as explained above by Josh,
using @sqlscript.sql in sqlplus is the best way but this technique might not work in all databases, instead you can modify your script like,
su - <db user>
connect to database <your db name >
(this again varies according to your db i.e. in db2 it is like db2 connect to , in oracle connect to etc)
for file in /home/user/sql_scripts/*.sql; do
echo "Executing $f.."
db2 -tvf "$f" <db2>
@"$f" <oracle/sqlplus etc>
done
modify above script as per your db and requirements.