Specifies the execution path a host language program will take when any embedded SQL statement results in one of these following exception conditions: o Row not found o An error condition o A warning condition For these conditions, the WHENEVER statement specifies that the program continue execution or branch to another part of the program.
1 – Environment
You can issue the WHENEVER statement only in host language programs.
2 – Format
(B)0[m[1;4mWHENEVER[m[1m qqwq> [1;4mNOT[m[1m [1;4mFOUND[m[1m qqwqqqqk [m [1m tq> [1;4mSQLERROR[m[1m qqqu x [m [1m mq> [1;4mSQLWARNING[m[1m qj x [m [1m lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1m mqwq> [1;4mCONTINUE[m[1m qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwq>[m [1m tq> [1;4mGOTO[m[1m qqwqwqwqqqqqqqwq> <host-label-name> qqu [m [1m mq> [1;4mGO[m[1m [1;4mTO[m[1m qj x mq> : qqj x [m [1m mqqqqqqqqqqq> <host-label-number> j [m [1m [m
3 – Arguments
3.1 – CONTINUE
Specifies that the program continue execution with the next sequential statement following the statement that generated an error.
3.2 – GOTO
Syntax options: host-label-name | host-label-number Specifies that the program branch to the statement identified by the host label. The form of the host label depends on the host language. You can use a colon (:) before a host label represented by a name, but not before a host label represented by a number.
3.3 – NOT_FOUND
Indicates the exception condition returned when SQL processes all the rows of a result table: o When a cursor referred to in a FETCH, UPDATE, or DELETE statement is positioned after the last row o When a query specifies an empty result table This is the same condition identified by a value of 100 in the SQLCODE variable, the value of '02000' in the SQLSTATE variable, and by the RDB$_STREAM_EOF error.
3.4 – SQLERROR
Indicates any error condition. For the SQLERROR argument of the WHENEVER statement, SQL defines an error condition as any condition that returns a negative value to SQLCODE.
3.5 – SQLWARNING
Indicates any warning condition.
4 – Example
Example 1: Using WHENEVER statements in a PL/I program /* When an SQL statement results in an RDB$_STREAM_EOF error, the program branches to LABEL_NOT_FOUND: */ EXEC SQL WHENEVER NOT FOUND GOTO LABEL_NOT_FOUND; /* When an SQL statement results in a warning severity error condition, the program branches to LABEL_ERROR: */ EXEC SQL WHENEVER SQLWARNING GOTO LABEL_ERROR; /* When an SQL statement results in an error severity exception condition, the program branches to LABEL_ERROR: */ EXEC SQL WHENEVER SQLERROR GOTO LABEL_ERROR;