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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How do I pass a return code from an Oracle script back to the WINDOWS Batch script which called it?

PhilMan2Jan 25 2020 — edited Jan 26 2020

I'm running Windows 10-64 bit and Oracle 18.4 I have a Windows batch file (test1.bat) which calls a windows SQL script file.

SQLPLUS -s (username)/(password) as sysdba @test1.sql Echo %errorlevel%

I would then like to do some error checking on the %errorlevel% variable when I'm returned to Test1.bat from SQLPLUS. I'll create different processes depending on whether the return code is ORA-01940 (Cannot drop a user that is currently connected) or ORA-01918 (user 'MYUSER' does not exist), etc.

When I run test1.bat, I can't reference the return code from Oracle SQLPLUS, even when the user was previously dropped. The batch script generates

>Echo 0 0

Here's the test1.sql

PROMPT Begin Dropping User Schema MyUser 
Alter Session
Set CONTAINER=(MyContainer);
Alter Session Set "_oracle_script"=true;
Whenever oserror exit 9;
Whenever sqlerror
exit sql.sqlcode;
DROP user MYUSER cascade;
EXIT;

How can I pass the error code from Oracle SQLPLUS back to the Windows batch script which called it?

Comments
Post Details
Added on Jan 25 2020
3 comments
1,063 views