Pl Sql Tutorial

Pl Sql Iterative Statements

Iterative control instructions will allow you to run many times a sequence of instructions.

LOOP ... END LOOP Statement

After each processing cycle, control returns to the beginning of the cycle and the instructions are executed again. The exit statement allows leaving cycle. Exit statement must be placed inside the cycle.

LOOP
  Sequence commands;
EXIT [WHEN condition];
END LOOP;

WHILE LOOP ... END LOOP Statement

Structures while-loop repeats a statement until such time as the condition becomes false.
Before each iteration, the condition is evaluated if the condition is TRUE, the instructions are executed, otherwise the instructions will not be executed.

WHILE condition LOOP
  Sequence commands 1;
  Sequence commands 2;
EXIT [WHEN condition];
END LOOP;

FOR LOOP ... END LOOP Statement

FOR LOOP allows browsing of a course of a specified number of times. The syntax of FOR LOOP statement is the following:

FOR var IN [REVERSE] min..max LOOP
  Sequence commands;
EXIT [WHEN cond];
END LOOP;