Database Reference
In-Depth Information
DECLARE
STEP INTEGER;
BEGIN
FOR STEP IN REVERSE -2..2 LOOP
DBMS_OUTPUT.PUT_LINE(TO_CHAR(STEP));
END LOOP;
END;
/
The third example shows the use of variables and expressions in FOR
loop range counters. The result is a FOR loop that iterates five times from 1
to 5.
DECLARE
STEP INTEGER;
J INTEGER DEFAULT 1;
K INTEGER DEFAULT 1;
BEGIN
FOR STEP IN J..(K+4) LOOP
DBMS_OUTPUT.PUT_LINE(TO_CHAR(STEP));
END LOOP;
END;
/
The last example shows use of labels and the loop EXIT command.
Note how the EXIT command forces control out of two nested loops. This
nested FOR loop will execute 10 times through the outer loop and from 1
to 10 times through the inner loop before being terminated by the EXIT
command.
DECLARE
OUTER INTEGER;
INNER INTEGER;
BEGIN
DBMS_OUTPUT.PUT_LINE('Start of Nested FOR loops');
<<outerloop>>
FOR OUTER IN 1..10 LOOP
FOR INNER IN 1..10 LOOP
IF OUTER > INNER THEN
EXIT outerloop;
Search WWH ::




Custom Search