Created
February 21, 2022 09:22
-
-
Save JoJoJotarou/2f80de5506be911d14964c398c2d037b to your computer and use it in GitHub Desktop.
mysql 存储过程获取异常、回滚、手动提交
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop procedure if exists catch_execption; | |
create procedure catch_execption(in V_ID bigint) | |
begin | |
DECLARE result varchar(100) DEFAULT '00000'; | |
DECLARE code CHAR(5); | |
DECLARE msg TEXT; | |
DECLARE EXIT HANDLER FOR SQLEXCEPTION | |
BEGIN | |
GET DIAGNOSTICS CONDITION 1 | |
code = RETURNED_SQLSTATE, msg = MESSAGE_TEXT; | |
ROLLBACK; | |
set result = CONCAT('call [pro_dr_archive] failed, error = ',code,', message = ',msg); | |
select result; | |
END; | |
start transaction ; | |
-- add your process | |
COMMIT; | |
select result; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment