|Oracle® Database PL/SQL Language Reference
11g Release 1 (11.1)
|PDF · Mobi · ePub|
EXIT statement exits a loop and transfers control to the end of the loop. The
EXIT statement has two forms: the unconditional
EXIT and the conditional
WHEN. With either form, you can name the loop to be exited.
If and only if the value of this expression is
TRUE, the current loop (or the loop labeled by
label_name) is exited immediately.
EXIT statement (that is, one without a
WHEN clause) exits the current loop immediately. Execution resumes with the statement following the loop.
Identifies the loop exit from: either the current loop, or any enclosing labeled loop.
EXIT statement can appear anywhere inside a loop, but not outside a loop. PL/SQL lets you code an infinite loop. For example, the following loop will never terminate normally so you must use an
EXIT statement to exit the loop.
WHILE TRUE LOOP ... END LOOP;
If you use an
EXIT statement to exit a cursor
FOR loop prematurely, the cursor is closed automatically. The cursor is also closed automatically if an exception is raised inside the loop.