Tech Tip: Handlers for SQL Routines
gorddbds 060001JCXS Visits (3596)
Handlers for SQL Routines.
A handler is usually a section of user declared code in an SQL routine that determines what to do when a condition occurs. DB2 will look for handler code for several conditions ranging from SQLWARNING to SQLEXCEPTION. One common type of handler is the NOT FOUND condition handler. When a record is not returned for a query or there are no more results DB2 will look for a NOT FOUND condition handler and turn control of the routine over to the section of code in this handler. This handler is often used to break out of loops that are fetching data or to test the SQLCODE or SQLSTATE returned. Starting with DB2 version 9.5, DB2 resets the value of SQLCODE and SQLSTATE after the first line of the handler is executed, so it is advised to save these values into variables in the first line of the handler.
For more information on the change in the NOT FOUND handler behavior please see the following technote.
For additional general information on handlers, see the following infocenter link.