Link to home
Create AccountLog in
Avatar of vamsi_uk
vamsi_uk

asked on

Run SQL statements and scripts from Windows batch file

Hi Experts,

I want to have a windows batch file which will run some sql commands or scripts when i execute the batch file. I have tried to create a simple batch file which will connect to the database and execute a sample SQL statement. But this is only connecting to the database and stops at the SQL prompt.

contents of the batch file:
##############################
set ORACLE_SID=db1
set ORACLE_INSTANCE=db1
sqlplus / as sysdba

@test.sql
##############################

Could someone please tell me how i can run sql statements or scripts from the batch file

Thanks
ASKER CERTIFIED SOLUTION
Avatar of schwertner
schwertner
Flag of Antarctica image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
One small addition: if you use a .sql extension for your sql files, then you can ignore the extension...

i.e.,
> sqlplus /nolog @test

where test.sql contains

-- log into sqlplus as sys
connect / as sysdba;
-- run sql stuff
.....
Avatar of vamsi_uk
vamsi_uk

ASKER

hi guys,

sorry for not responding quickly as i was away on work. I will test your suggestions today and let you know how it goes.

thanks
thanks guys, that worked fine