PL/SQL GOTO Statement
The PL/SQL GOTO
statement is used to jump to perform specific tast in the same sub section of PL/SQL section. The label statement is declared and decorated like <<label>>.
PL/SQL Continue Statement Syntax
To jump to perform specific tast in the same sub section of PL/SQL section, use the following syntax:
Syntax
<>
..
..
GOTO label_name;
Statement;
PL/SQL GOTO Statement example
The following PL/SQL show how to jump to perform specific tast in the same sub section of PL/SQL section:
Example
DECLARE
counter number(2) := 10;
BEGIN
<<mylabel>>
WHILE counter < 50 LOOP
dbms_output.put_line ('value of Counter: ' || counter);
counter := counter + 1;
IF counter = 40 THEN
counter := counter + 1;
GOTO mylabel;
END IF;
END LOOP;
END;
Restriction on GOTO statement
There are some restrictions while using the PL/SQL GOTO statement some are:
- You cannot use a GOTO statement to an IF statement, CASE statement, LOOP statement or sub-block
- You cannot use a GOTO statement to out of the subprogram
- You cannot use a GOTO statement into an exception handler
- You cannot use a GOTO statement to an outer block into a sub-block
- You cannot use a GOTO statement to branch from one IF clause to another