Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MySQL Stored Procedure Error Handling
- DELIMITER $$
- CREATE PROCEDURE `myProcedure`(OUT o_error_status varchar(50))
- MY_BLOCK: BEGIN
- DECLARE EXIT handler for 1062 set o_error_status := "Duplicate entry in table";
- DECLARE EXIT handler for 1048 set o_error_status := "Trying to populate a non-null column with null value";
- -- declare handlers ad nauseum here....
- DECLARE EXIT handler for sqlexception set o_error_status:= "Generic SQLException. You'll just have to figure out the SQLSTATE yourself...." ;
- -- Procedure logic that might error to follow here...
- END MY_BLOCK$$
- SHOW ERRORS LIMIT 1 -- for SQL-state > 2
- SHOW WARNINGS LIMIT 1 -- for SQL-state 1,2
- DECLARE EXIT HANDLER FOR SQLSTATE SQLEXCEPTION .....;
- SELECT RAISE_ERROR_unable_to_update_basket;
- ERROR 1054 (42S22): Unknown column 'RAISE_ERROR_unable_to_update_basket' in 'field list'
Add Comment
Please, Sign In to add comment