Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle 11g - run windows batch file to run multiple sql files in sqlplus

I would like to use a single batch file to execute multiple sql in a sequence.. IE: sql2 script calls a table created by sql1 script.. etc..

here is the batch code I have so far.. it works to run a single sql file but I need it to run the first one and then then next.. thanks in advance.

    @ECHO OFF
echo.
echo.
SET /P uname=Username:
echo.
echo.
SET /P pass=Password:
echo.
echo.
SET /P mydatabase=Database:
echo.
echo.
set oracle_sid=ins

sqlplus -s %uname%/%pass%@%mydatabase% @J:/A/scripts/_TABLES/Table1_.sql \n
sqlplus -s %uname%/%pass%@%mydatabase% @J:/A/scripts/_TABLES/Table2_.sql \n
sqlplus -s %uname%/%pass%@%mydatabase% @J:/A/scripts/_TABLES/Table3_.sql \n
sqlplus -s %uname%/%pass%@%mydatabase% @J:/A/scripts/_TABLES/Table4_.sql \n
sqlplus -s %uname%/%pass%@%mydatabase% @J:/A/scripts/_TABLES/Table5_.sql \n
sqlplus -s %uname%/%pass%@%mydatabase% @J:/A/scripts/_TABLES/Table6_.sql \n
sqlplus exit
pause
like image 532
SeattleGray Avatar asked Oct 21 '25 07:10

SeattleGray


1 Answers

make a 'driver' sql script.

inside it would look similar to this:

@Table1_.sql
@Table2_.sql
@Table3_.sql
@Table4_.sql

then just call this one once from the OS

like image 178
Randy Avatar answered Oct 23 '25 20:10

Randy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!