Declare | CURSOR cursor_name IS select_statement; | • Do not include an INTO clause. • If processing in a specific order is important, use and ORDER BY clause. |
Open | OPEN cursor_name; | • Opening the cursor executes the query and identifies the active set • If the query returns no rows, no exception is raised • Use cursor attributes to test the outcome after a fetch |
Fetch | FETCH cursor_name INTO [variable1, variable2, . . .] | [record_name]; | • Within a loop, fetch one record at a time until empty. • Retrieves the current row values into variables • Include the same number of variables and in the same order as the columns • Test to see if the cursor contains rows. |
Cursor FOR Loop | FOR record_name IN cursor_name LOOP statements; END LOOP; | • Implicit open, fetch, and close occur • The record is implicitly declared. |
Close | CLOSE cursor_name; | • Close after done processing • Re-open if necessary • Do not attempt to fetch data after the cursor is closed |