Link to home
Create AccountLog in
Avatar of HubertFarnsworth
HubertFarnsworthFlag for United States of America

asked on

Can Oracle script (SQL) file issue an EXIT?

Good Day, Experts -

Is there a way for a .SQL file being run in SQL Plus to exit? Here is what I have to accomplish...

UPGRADE.SQL contains the following:

    IF MyPKG.IsUpdateAllowed( ) = FALSE THEN
        EXIT; -- I want to stop the remainder of the script from firing
    END IF;
.... the rest of my DML appears here in the script... I don't want this to fire if the previous PKG procedure returned FALSE.

Is there a way to do this?

Avatar of HubertFarnsworth
Flag of United States of America image


I failed to mention (clearly) that UPGRADE.SQL is run via SQLPlus.
Avatar of Sean Stuber
Sean Stuber

sqlplus itself can't do conditionals but your dml could be executed within pl/sql blocks  where you can wrap them in if/else conditions.
I had tried that and it works for DML, but, my scripts sometime contain DDL, too. I would need to make all of that dynamic, right? I believe that's the only way to block DDL.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
This worked beautifully. Thanks.
No problem.  Glad to help.