•For NOT FOUND  conditions, if the condition was raised normally, the action is CONTINUE . If it was raised by SIGNAL  or RESIGNAL , the action is EXIT . 

The following examples demonstrate how MySQL applies the handler selection rules. 

This procedure contains two handlers, one for the specific SQLSTATE  value ( ’42S02’ ) that occurs for attempts to drop a nonexistent table, and one for the general SQLEXCEPTION  class: 

CREATE PROCEDURE p1() BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE ’42S02’ SELECT ’SQLSTATE handler was activated’ AS msg; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT ’SQLEXCEPTION handler was activated’ AS msg; DROP TABLE test.t; END; 

Both handlers are declared in the same block and have the same scope. However, SQLSTATE  handlers take precedence over SQLEXCEPTION  handlers, so if the table t  is nonexistent, the DROP TABLE statement raises a condition that activates the SQLSTATE  handler: 

mysql> CALL p1(); +--------------------------------+ | msg | +--------------------------------+ | SQLSTATE handler was activated | +--------------------------------+ 

This procedure contains the same two handlers. But this time, the DROP TABLE  statement and SQLEXCEPTION  handler are in an inner block relative to the SQLSTATE  handler: CREATE PROCEDURE p2() 

BEGIN -- outer block DECLARE CONTINUE HANDLER FOR SQLSTATE ’42S02’ SELECT ’SQLSTATE handler was activated’ AS msg; BEGIN -- inner block DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT ’SQLEXCEPTION handler was activated’ AS msg; DROP TABLE test.t; -- occurs within inner block END; END; 

In this case, the handler that is more local to where the condition occurs takes precedence. The SQLEXCEPTION  handler activates, even though it is more general than the SQLSTATE  handler: 

mysql> CALL p2(); +------------------------------------+ | msg | +------------------------------------+ | SQLEXCEPTION handler was activated | +------------------------------------+ 

In this procedure, one of the handlers is declared in a block inner to the scope of the DROP TABLE statement: 

CREATE PROCEDURE p3() BEGIN -- outer block DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT ’SQLEXCEPTION handler was activated’ AS msg; BEGIN -- inner block DECLARE CONTINUE HANDLER FOR SQLSTATE ’42S02’ SELECT ’SQLSTATE handler was activated’ AS msg; 

