Errors Associated with Select and Function Cursors
Because the database server is seeing the query for the first time, it might detect errors. In this case, it does not actually return the first row of data, but it resets the SQLCODE variable and the sqlca.sqlcode field of the sqlca. The value is either negative or zero, as the following table describes.
- Code Value
- Significance
- Negative
- An error was detected in the SELECT statement
- Zero
- The SELECT statement is valid
Unlike ESQL/C routines, SPL routines do not have direct access to the sqlca structure. An ESQL/C routine must invoke the built-in SQLCODE function explicitly to access the return code of the SELECT, EXECUTE FUNCTION, or EXECUTE PROCEDURE statement associated with the cursor that OPEN references.
If the SELECT, SELECTFOR UPDATE, EXECUTE FUNCTION (or EXECUTE
PROCEDURE) statement is valid, but no rows match its criteria, the
first FETCH statement returns a value of
100
(SQLNOTFOUND
),
meaning that no rows were found. Tip: When
you encounter an SQLCODE error, a corresponding SQLSTATE error
value also exists. For information about how to view the message text,
refer to Using the SQLSTATE Error Status Code.