In this post, you’ll learn about the error message -227 fetch fetch-orientation is not allowed, because cursor cursor-name has an unknown position (sqlcode,sqlstate) in the IBM DB2 database , the reason why it occurs along with the solution to fix it
IBM DB2 Error Message
-227 fetch fetch-orientation is not allowed, because cursor cursor-name has an unknown position (sqlcode,sqlstate)
Reason for the Error
The cursor position for cursor-name is unknown. The previous multiple-row FETCH for cursor cursor-name resulted in an error (SQLCODE sqlcode, SQLSTATE sqlstate) in the middle of processing multiple rows that were retrieved from DB2. One or more of the requested rows could not be returned to the program following the error, leaving the position of the cursor unknown.
Solution
Close and reopen the cursor to reset the position. For scrollable cursors, you can change the FETCH statement to specify one of the other fetch orientations (such as FIRST, LAST, BEFORE, AFTER, or ABSOLUTE) to establish a valid cursor position and fetch a row of data.