Oracle pl sql goto statement tutorial

Pl sql goto statement:

The pl sql goto statement provides an unconditional jump from the GOTO to a labeled statement in the same subprogram. A label can be declare with the << label >> syntax.

pl sql goto statement syntax:

GOTO label_name;  
 //Other statements  
<<label_name>>  
Statement;

Pl sql goto statement example:

DECLARE
   num number := 1;
BEGIN
   <<loop1>>
   -- while loop execution 
   WHILE num <= 10 LOOP
      dbms_output.put_line ('Value of num: ' || num);
      num := num + 1;
      IF num = 5 THEN
         num := num + 1;
         GOTO loop1;
      END IF;
   END LOOP;
END;
/

Output:

Value of num: 1
Value of num: 2
Value of num: 3
Value of num: 4
Value of num: 6
Value of num: 7
Value of num: 8
Value of num: 9
Value of num: 10

Pl sql goto statement restrictions:

1. GOTO statement cannot transfer control into an IF statement, CASE statement, LOOP statement or sub-block.
2. GOTO statement cannot transfer control from one IF statement clause to another or from one CASE statement WHEN clause to another.
3. GOTO statement cannot transfer control from an outer block into a sub-block.
4. GOTO statement cannot transfer control out of a subprogram.
5. GOTO statement cannot transfer control into an exception handler.