4

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
SeattleGray
  • 95
  • 1
  • 3
  • 10

2 Answers2

10

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

Randy
  • 16,480
  • 1
  • 37
  • 55
  • How could I pass parameters received in this SQL file (&1,&2 and &3 for example) to the four files launched ? – Benobab Feb 04 '16 at 09:47
  • To run the 'driver' SQL script open a command-line and run with SQLPlus: "sqlplus username/password@sid @{path-to-driver-sql-script}\driver.sql" – Binyamin Regev Jun 26 '17 at 15:31
0

Or you can run them all together.

cat Table1_.sql > /tmp/temp.sql
cat Table1_.sql >> /tmp/temp.sql
cat Table1_.sql >> /tmp/temp.sql
sqlplus USERNAME/PASSWORD@DOMAIN @/tmp/temp.sql
Cyva
  • 1,057
  • 10
  • 9