mysql异常处理
CREATE DEFINER=`root`@`localhost` PROCEDURE `pr_exception`(i_date varchar(10),out o_error_code varchar(200),out o_error_msg varchar(200)) BEGIN -- 自定义异常 DECLARE my_error CONDITION FOR SQLSTATE '45000'; DECLARE EXIT HANDLER FOR my_error begin set o_error_code:=-100,o_error_msg:='自定义错误信息'; ROLLBACK ; end; -- 定义异常 DECLARE EXIT HANDLER for SQLEXCEPTION BEGIN GET DIAGNOSTICS CONDITION 1 o_error_code = RETURNED_SQLSTATE, o_error_msg = MESSAGE_TEXT; rollback; -- 回滚 END; START TRANSACTION; -- 开启事务 if i_date ='0' then SIGNAL my_error; -- 触发自定义异常 end if; insert into acc_cellstk (fundid_) values(1); -- 正确sql insert into acc_cellstk (fundid_) values('s'); -- 错误sql 引发异常 commit; END