Is there are method in PL/SQL to exit from the procedure if a condition is met?
I need to change my procedure to check the existance of a particular value, however I have several hundred lines of code. Is there is a simple exit statement or goto statement that will jump to or exit based on a condition?
select count(*) into x_var from table where field=x;
if x_var = 1 then
"EXIT" statement can be used only within a loop. Do you use it? Cursor loop, for example? Then you can use EXIT WHEN cursor%NOTFOUND. Simple IF condition would also work - IF your_condition THEN EXIT; END IF;
If you don't have a loop, you could use a GOTO statement, such as
SELECT COUNT(*) INTO x FROM EMP;
IF x > 100 THEN
I *think* there's no way to exit a PL/SQL procedure with a single statement. Or is there? Perhaps someone else will know.
SQL> create or replace procedure p is
SQL> exec p
PL/SQL procedure successfully completed.