Database Reference
In-Depth Information
24.7.2.1
The FOR Loop
Loops a known number of times and can be aborted using the EXIT
WHEN clause. The range values can be integers, variables containing inte-
gers, or expressions resulting in integer values. The syntax of the FOR loop
is shown in Figure 24.18.
Following are some example FOR loops. Example screenshots are not
included for these FOR loop examples. The first example counts forward
from 1 to 5.
DECLARE
STEP INTEGER;
BEGIN
FOR STEP IN 1..5 LOOP
DBMS_OUTPUT.PUT_LINE(TO_CHAR(STEP));
END LOOP;
END;
/
The second example counts in reverse from 2 back to -2. Note how
even the reverse-counting loop places the lower-valued integer first and the
higher-valued integer last. This is shown in the syntax diagram for the FOR
loop in Figure 24.18.
Figure 24.18
FOR Loop
Statement Syntax.
 
Search WWH ::




Custom Search