0

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

How can I pass the error code from Oracle SQLPLUS back to the batch script which called it? Here's the test1.sql

PROMPT Begin Dropping User Schema MyUser
Alter Session Set CONTAINER=(MyContainer);
Alter Session Set "_oracle_script"=true;
DROP user MYUSER cascade;
Whenever sqlerror exit sql.sqlcode;
EXIT;
Compo
  • 36,585
  • 5
  • 27
  • 39
user3138025
  • 795
  • 4
  • 17
  • 46
  • Hello Compo. I'm trying to understand why you closed this. The example you gave me is for a UNIX environment. I'm using Windows Batch. The UNIX example isn't helpful. Should I just resubmit the question again? – user3138025 Jan 25 '20 at 19:21
  • Apologies, I had another question open in another tab and posted the wrong link. Unfortunately I cannot locate it again at the moment, so have decided to reopen it until or if I do. – Compo Jan 25 '20 at 20:36
  • 2
    Does this answer your question? [How do I pass a return code from an Oracle script back to the WINDOWS Batch script which called it?](https://stackoverflow.com/questions/59912822/how-do-i-pass-a-return-code-from-an-oracle-script-back-to-the-windows-batch-scri) – Alex Poole Jan 25 '20 at 20:50
  • Hello Compo. I created a new discussion prior to your re-opening this one, so we have two discussions now. I think this one (https://stackoverflow.com/questions/59911257/how-do-i-pass-a-return-code-from-oracle-sql-script-back-to-the-batch-script-whic) can be deleted. However, please leave (https://stackoverflow.com/questions/59912822/how-do-i-pass-a-return-code-from-an-oracle-script-back-to-the-windows-batch-scri/59913172#59913172) intact it was already answered by Alex Poole and it's correct. – user3138025 Jan 25 '20 at 20:58

0 Answers0