Cursor FOR Loop v12
In the cursor examples presented so far, the programming logic required to process the result set of a cursor included a statement to open the cursor, a loop construct to retrieve each row of the result set, a test for the end of the result set, and finally a statement to close the cursor. The cursor FOR loop is a loop construct that eliminates the need to individually code the statements just listed.
The cursor FOR
loop opens a previously declared cursor, fetches all rows in the cursor result set, and then closes the cursor.
The syntax for creating a cursor FOR
loop is as follows.
record
is an identifier assigned to an implicitly declared record with definition, cursor%ROWTYPE
. cursor
is the name of a previously declared cursor. statements
are one or more SPL statements. There must be at least one statement.
The following example shows the example from %NOTFOUND, modified to use a cursor FOR
loop.
The same results are achieved as shown in the output below.