Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem in connecting to sqlplus from windows batch file (DOS)

611496Jun 22 2009 — edited Jun 22 2009
Hi All,
We have a new 10g Oracle database installed on windows server. I am trying to write a windows batch file to
1) Connect to SQLPLUS
2) Execute a script
3) Disconnect from SQLPLUS.
-----------------------------------------------------------------------------------
Example File Name:- execsql.bat

SET ORACLE_SID=CAUT
SET SCHEMA_IN=%1
SET PASS=DEV
SET script=%2

sqlplus %SCHEMA_IN%/%PASS%@%ORACLE_SID% @%script%

if %errorlevel% NEQ 0 echo ERROR: %ERRORLEVEL% else echo OK
------------------------------------------------------------------------------------------------
Now if i run this bat file like :- execsql.bat DEV script1.sql
DEV= schema name,
script1.sql = this file contains select * from dual;

The code runs fine, but if i change dual to dual1 the sql error's out but not able to catch the error in the batch file.

Reason why i would like to catch the error is this batch file would be scheduled through Autosys job scheduler and for autosys any exit code >0 is an error. Please help me in rewriting this batch script.

Thanks
Sam.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2009
Added on Jun 22 2009
2 comments
832 views