Database Reference
In-Depth Information
IF Condition THEN
EXIT;
END IF;
END LOOP;
8.8.2 WHILE Loops
The WHILE loop executes as long as the mentioned Boolean condition evaluates to TRUE.
It has the following syntax:
WHILE condition LOOP
statement 1;
statement 2;
..................
statement n;
END LOOP;
The reserved word WHILE is used to start a loop construct. Then condition is evaluated
to TRUE or FALSE. The result of evaluation decides whether the loop is executed or not.
Statements 1 through n, are executed repeatedly. The END LOOP is a reserved phrase used
to terminate loop construct.
Example 7: Print numbers from 1 to 10
DECLARE
counter NUMBER := 1;
BEGIN
WHILE counter <= 10 LOOP
DBMS_OUTPUT.PUT_LINE (' '||counter);
counter := counter + 1;
END LOOP;
END;
8.8.3 FOR Loop
A numeric FOR loop is called numeric because it needs an integer value to terminate loop.
The numeric FOR loop is the traditional and familiar “counted” loop. The number of it-
erated of the FOR loop is known when the loop starts; it is specified in the range scheme
found between the FOR and LOOP keywords in the boundary. Do not declare the loop
index. PL/SQL automatically and implicitly declares it as a local variable with datatype
INTEGER. It has the following syntax:
FOR loop_counter IN [REVERSE] lowest_number ....highest_number LOOP
Search WWH ::




Custom Search