iierrornumber and iirowcount Variables
The iierrornumber and iirowcount variables, in conjunction with the RAISE ERROR statement, handle errors in database procedures.
The iirowcount variable contains the number of rows affected by the last executed SQL statement. The iierrornumber variable contains the error number (if any) associated with the execution of a database procedure statement.
Because both iierrornumber and iirowcount reflect the results of the preceding query, beware of inadvertently resetting the value of one when checking the other.
The following example from a database procedure illustrates this error:
...
update emp set ...
/* The following statement resets iierrornumber, which will reflect the results of the second statement and not the first, as desired. */
/* wrong way to check iirowcount */
rcount = iirowcount;
/* The error number reflects the results of the preceding assignment, not the update statement */
enumber = iierrornumber;
The following example illustrates the correct way to check iierrornumber and iirowcount: select both values into variables, and then check the contents of the variables (because iierrornumber and iirowcount is reset to reflect the results of the SELECT statement).
...
update emp set ...
/* right way to check iirowcount (using select) */
select iirowcount, iierrornumber into rcount, enumber;
The following table lists the values of iirowcount and iierrornumber after the successful or unsuccessful execution of an SQL statement:
The execution of each database procedure statement sets the value of iierrornumber either to zero (no errors) or an error number. To check the execution status of any particular statement, iierrornumber must be examined immediately after the execution of the statement.
Errors occurring in IF, WHILE, MESSAGE, and RETURN statements do not set iierrornumber. However, any errors that occur during the evaluation of the condition of an IF or WHILE statement terminate the procedure and return control to the calling application.