PL/SQL LOOP Construct
Oracle提供三种样式的Loop结构
1. The Basic Loop
The BASIC loop repeats until a condition is met. Because the condition is tested at the end of the loop, the BASIC loop will always execute at least once.
A simple loop runs until you explicitly end the loop. The syntax for a simple loop is as follows:
To end the loop, you use either an EXIT or EXIT WHEN statement.
The EXIT statement ends a loop immediately.
EXIT WHEN statement ends a loop when a specified condition occurs.
Sample
2. The FOR Loop
The FOR loop repeats, incrementing or decrementing its internal counter until the counter reaches its pre-programmed limit, set by thelower_bound and higher_bound parameters.Sample
3. The WHILE Loop
The WHILE loop repeats until a given condition is met. If the condition is not met it will repeat forever. If thecondition is met or satisfied before the loop begins, it will not execute at all.WHILE condition LOOP statement_1; statement_2; . . . statement_n; END LOOP;
Example