want to run multiple SQL script file in one go with in SQLPLUS

rahul jain picture rahul jain · Mar 27, 2014 · Viewed 45.1k times · Source

I have to run multiple SQL script file in one go.

Like every time i have to write command in SQLPLUS

SQL>@d:\a.txt 
SQL>@d:\a2.txt
SQL>@d:\a3.txt
SQL>@d:\a4.txt

is there any way put all file in one folder & run all script file in one go without missing any single file like @d:\final.txt or @d\final.bat

Answer

a_horse_with_no_name picture a_horse_with_no_name · Mar 27, 2014

There is no single SQL*Plus command to do that, but you can create a single script that calls all the others:

Put the following into a batch file

@echo off
echo.>"%~dp0all.sql"
for %%i in ("%~dp0"*.sql) do echo @"%%~fi" >> "%~dp0all.sql"

When you run that batch file it will create a new script named all.sql in the same directory where the batch file is located. It will look for all files with the extension .sql in the same directory where the batch file is located.

You can then run all scripts by using sqlplus user/pwd @all.sql (or extend the batch file to call sqlplus after creating the all.sql script)