Declaring a Condition and Handler in action : Condition HANDLER « Procedure Function « SQL / MySQL






Declaring a Condition and Handler in action

 
mysql>
mysql>
mysql> DELIMITER //
mysql>
mysql> CREATE FUNCTION perform_logic (some_input INT(10)) returns INT(10)
    -> BEGIN
    ->         DECLARE problem CONDITION FOR 1265;
    ->         DECLARE EXIT HANDLER FOR problem
    ->                 RETURN NULL;
    ->
    ->         # do some logic, if the problem condition is met
    ->         # the function will exit, returning a NULL
    ->
    ->         RETURN 1;
    -> END
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;
mysql>
mysql> drop function perform_logic;
Query OK, 0 rows affected (0.00 sec)

mysql>

        








Related examples in the same category

1.Declaring a Condition and Handler
2.DECLARE CONTINUE HANDLER FOR NOT FOUND SET
3.Checking flag
4.Using while to check the condition
5.DECLARE EXIT HANDLER FOR
6.Checking Exit flag
7.Using the IF statement to verify 'CONTINUE HANDLER'
8.The example associates a handler with SQLSTATE 23000, which occurs for a duplicate-key error
9.To ignore a condition