14.17 Cursor FOR LOOP Statement
LOOP statement implicitly declares its loop index as a record variable of the row type that a specified cursor returns, and then opens a cursor.
With each iteration, the cursor
LOOP statement fetches a row from the result set into the record. When there are no more rows to fetch, the cursor
LOOP statement closes the cursor. The cursor also closes if a statement inside the loop transfers control outside the loop or raises an exception.
Name for the loop index that the cursor
LOOP statement implicitly declares as a
%ROWTYPE record variable of the type that
record is local to the cursor
LOOP statement. Statements inside the loop can reference
record and its fields. They can reference virtual columns only by aliases. Statements outside the loop cannot reference
record. After the cursor
LOOP statement runs,
record is undefined.
Name of an explicit cursor (not a cursor variable) that is not open when the cursor
LOOP is entered.
Actual parameter that corresponds to a formal parameter of
SELECT statement (not PL/SQL
INTO statement). For
select_statement, PL/SQL declares, opens, fetches from, and closes an implicit cursor. However, because
select_statement is not an independent statement, the implicit cursor is internal—you cannot reference it with the name
Oracle Database SQL Language Reference for
SELECT statement syntax
Label that identifies
cursor_for_loop_statement (see "statement ::=" and "label").
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
LOOP statement matches a label at the beginning of the same
LOOP statement (the compiler does not check).
Example 7-18, "Implicit Cursor FOR LOOP Statement"
Example 7-19, "Explicit Cursor FOR LOOP Statement"
Example 7-20, "Passing Parameters to Explicit Cursor FOR LOOP Statement"
Example 7-21, "Cursor FOR Loop References Virtual Columns"
In this chapter:
In other chapters: