Condition and Handler in action : Condition HANDLER : Procedure Function MySQL TUTORIALS


MySQL TUTORIALS » Procedure Function » Condition HANDLER »

 

Condition and Handler in action


By declaring conditions and handlers, you can catch certain MySQL errors or SQLSTATE conditions.

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, rows affected (0.00 sec)

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

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Procedure Function
» Condition HANDLER