| Oracle® Database PL/SQL Language Reference 11g Release 2 (11.2) Part Number E17126-03 |
|
|
View PDF |
The WHILE LOOP statement runs one or more statements while a condition is TRUE. The WHILE LOOP statement ends when the condition becomes FALSE or NULL, when a statement inside the loop transfers control outside the loop, or when PL/SQL raises an exception.
Topics:
Syntax
See:
Semantics
boolean_expression
This expression is evaluated at the beginning of each iteration of the loop. If its value is TRUE, the statements after LOOP run. Otherwise, control transfers to the statement after the WHILE LOOP statement.
statement
To prevent an infinite loop, at least one statement must change the value of boolean_expression to FALSE or NULL, or transfer control outside the loop. The statements that can transfer control outside the loop are:
"CONTINUE Statement" (when it transfers control to the next iteration of an enclosing labeled loop)
label
A label that identifies while_loop_statement (see "statement ::=" and "label"). CONTINUE, EXIT, and GOTO statements can reference this label.
Labels improve readability, especially when LOOP statements are nested, but only if you ensure that the label in the END LOOP statement matches a label at the beginning of the same LOOP statement (the compiler does not check).
Examples
Related Topics
In this chapter:
In other chapters: