Loop with label : Loop « PL SQL « Oracle PL / SQL






Loop with label

  
SQL>
SQL>
SQL> DECLARE
  2     lv_counter_num PLS_INTEGER := 0;
  3  BEGIN
  4     <<LOOP1>>
  5     LOOP
  6        <<LOOP2>>
  7        LOOP
  8           lv_counter_num := lv_counter_num + 1;
  9           DBMS_OUTPUT.PUT_LINE('Counter: ' ||lv_counter_num);
 10           EXIT LOOP1 WHEN lv_counter_num = 3;
 11        END LOOP LOOP2;
 12           DBMS_OUTPUT.PUT_LINE('Exited LOOP2');
 13     END LOOP LOOP1;
 14           DBMS_OUTPUT.PUT_LINE('Exited LOOP1');
 15  END;
 16  /
Counter: 1
Counter: 2
Counter: 3
Exited LOOP1

PL/SQL procedure successfully completed.

SQL>

   
  








Related examples in the same category

1.Use EXIT WHEN to exit a loop
2.Empty Loop statement
3.unconstrained loop
4.LOOP..END LOOP, Cursor Loop
5.Insert a row into MyTable with the current value of the loop counter.
6.An anonymous block demonstrates a guard on exit simple loop