An anonymous block demonstrates a guard on exit simple loop : Loop « PL SQL « Oracle PL / SQL






An anonymous block demonstrates a guard on exit simple loop

   
SQL>
SQL> DECLARE
  2    counter NUMBER;
  3    first   BOOLEAN;
  4  BEGIN
  5    LOOP
  6      IF NVL(counter,1) >= 1 THEN
  7        IF NOT NVL(first,TRUE) THEN
  8          counter := counter + 1;
  9        ELSE
 10          counter := 1;
 11          first := FALSE;
 12        END IF;
 13      END IF;
 14      dbms_output.put_line('Iteration ['||counter||']');
 15
 16      EXIT WHEN NOT counter < 3;
 17    END LOOP;
 18  END;
 19  /
Iteration [1]
Iteration [2]
Iteration [3]

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 with label
5.LOOP..END LOOP, Cursor Loop
6.Insert a row into MyTable with the current value of the loop counter.