Host language variables cannot be used in an embedded Whenever statement.
All users are permitted to use this statement.
In general, the Whenever statement has no impact. However, if the specified action is stop, any locks held are dropped because this action terminates execution of the program.
The following examples describe how to enable your application to handle error and exception conditions arising from embedded SQL database statements.
exec sql whenever sqlerror call sqlprint;
exec sql open cursor1;
exec sql whenever not found goto close_cursor;
loop until whenever not found is true
exec sql fetch cursor1
into :var1, :var2;
print and process the results;
end loop;
close_cursor:
exec sql whenever not found continue;
exec sql close cursor1;
exec sql whenever sqlerror stop;
exec sql whenever sqlwarning stop;
error_handle:
exec sql whenever sqlerror continue;
exec sql whenever sqlwarning continue;
exec sql whenever not found continue;
...
handle cleanup;
...
exec sql whenever sqlerror stop;
exec sql connect :dbname;
exec sql whenever sqlerror continue;
exec sql whenever sqlmessage continue;
...
exec sql execute procedure proc1;