Handler declarations must appear after variable or condition declarations. 

The handler_action  value indicates what action the handler takes after execution of the handler statement: 

• CONTINUE : Execution of the current program continues. 

• EXIT : Execution terminates for the BEGIN ... END  compound statement in which the handler is declared. This is true even if the condition occurs in an inner block. 

• UNDO : Not supported. 

The condition_value  for DECLARE ... HANDLER  indicates the specific condition or class of conditions that activates the handler. It can take the following forms: 

• mysql_error_code : An integer literal indicating a MySQL error code, such as 1051 to specify “unknown table” : 

DECLARE CONTINUE HANDLER FOR 1051 BEGIN -- body of handler END; 

Do not use MySQL error code 0 because that indicates success rather than an error condition. For a list of MySQL error codes, see Server Error Message Reference. 

•SQLSTATE [VALUE] sqlstate_value : A 5-character string literal indicating an SQLSTATE value, such as ’42S01’  to specify “unknown table” : 

DECLARE CONTINUE HANDLER FOR SQLSTATE ’42S02’ BEGIN -- body of handler END; 

Do not use SQLSTATE values that begin with ’00’  because those indicate success rather than an error condition. For a list of SQLSTATE values, see Server Error Message Reference. 

• condition_name : A condition name previously specified with DECLARE ... CONDITION . A condition name can be associated with a MySQL error code or SQLSTATE value. See Section 13.6.7.1, “DECLARE ... CONDITION Statement” . 

• SQLWARNING : Shorthand for the class of SQLSTATE values that begin with ’01’ . 

DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN -- body of handler END; 

• NOT FOUND : Shorthand for the class of SQLSTATE values that begin with ’02’ . This is relevant within the context of cursors and is used to control what happens when a cursor reaches the end of a data set. If no more rows are available, a No Data condition occurs with SQLSTATE value ’02000’ . To detect this condition, you can set up a handler for it or for a NOT FOUND  condition. 

DECLARE CONTINUE HANDLER FOR NOT FOUND BEGIN -- body of handler END; 

For another example, see Section 13.6.6, “Cursors” . The NOT FOUND  condition also occurs for SELECT ... INTO var_list  statements that retrieve no rows. 

