Using a cursor FOR loop v16
The programming logic required to process the result set of a cursor usually includes 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 a statement to close the cursor. The cursor FOR loop is a loop construct that eliminates the need to individually code these statements.
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 is the name of a previously declared cursor.
statements are one or more SPL statements. There must be at least one statement.
This example uses a cursor
The following is the output from this procedure: