If all the values from a cursor have been fetched and another fetch is issued,what the output will be?
-
Error
-
Last record
-
First record
-
Can't be decided.
When all rows have been fetched from a cursor and another fetch is issued, the cursor continues to return the last record. It does not throw an error or return to the first record.
In embedded/host-language SQL cursor processing (e.g. DB2/Oracle Pro*C style FETCH semantics), fetching past the last row sets an end-of-data indicator (SQLCODE +100 in DB2, %NOTFOUND=TRUE in PL/SQL) rather than raising a hard error, and — critically — the host variables named in the FETCH's INTO clause are NOT overwritten or cleared by the failed fetch. They simply retain whatever values were placed into them by the last successful fetch. So the practical 'output' observed after fetching past the end of a cursor is that the variables still show the last successfully fetched record's data unchanged. This matches 'Last record,' not an error, and not the first record (there's no wraparound), and the behavior is well-defined (not 'can't be decided').