PL/SQL: Loops Cheat Sheet

Basic Loop
LOOP 
   Sequence of statements; 
END LOOP; 
WHILE Loop
WHILE condition LOOP 
   sequence_of_statements 
END LOOP; 
FOR Loop
FOR counter IN initial_value .. final_value LOOP 
   sequence_of_statements; 
END LOOP;
Nested Loops
  • Nested basic LOOP
LOOP 
   Sequence of statements1 
   LOOP 
      Sequence of statements2 
   END LOOP; 
END LOOP;
  • Nested FOR LOOP 
FOR counter1 IN initial_value1 .. final_value1 LOOP 
   sequence_of_statements1 
   FOR counter2 IN initial_value2 .. final_value2 LOOP 
      sequence_of_statements2 
   END LOOP; 
END LOOP;
  • Nested WHILE LOOP
WHILE condition1 LOOP 
   sequence_of_statements1 
   WHILE condition2 LOOP 
      sequence_of_statements2 
   END LOOP; 
END LOOP; 
EXIT statement 
EXIT;
CONTINUE statement
CONTINUE;
GOTO statement 
GOTO label;
..
..
<< label >>
statement;

Leave a Reply

Your email address will not be published. Required fields are marked *