Condition Handling 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: The  condition_value  for  DECLARE ... HANDLER  indicates the specific condition or class of conditions that activates the handler. It can take the following forms: 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. 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. 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. 2808 • 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. • SQLWARNING : Shorthand for the class of SQLSTATE values that begin with  ’01’ • 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” . DECLARE CONTINUE HANDLER FOR NOT FOUND BEGIN -- body of handler END; DECLARE CONTINUE HANDLER FOR SQLWARNING BEGIN -- body of handler END; DECLARE CONTINUE HANDLER FOR SQLSTATE ’42S02’ BEGIN -- body of handler END; DECLARE CONTINUE HANDLER FOR 1051 BEGIN -- body of handler END; •SQLSTATE [VALUE]  sqlstate_value : A 5-character string literal indicating an SQLSTATE value, such as  ’42S01’  to specify “unknown table” : • mysql_error_code : An integer literal indicating a MySQL error code, such as 1051 to specify “unknown table” : • UNDO : Not supported. • 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. • CONTINUE : Execution of the current program continues.