Skip to content

Instantly share code, notes, and snippets.

@JoJoJotarou
Created February 21, 2022 09:22
Show Gist options
  • Save JoJoJotarou/2f80de5506be911d14964c398c2d037b to your computer and use it in GitHub Desktop.
Save JoJoJotarou/2f80de5506be911d14964c398c2d037b to your computer and use it in GitHub Desktop.
mysql 存储过程获取异常、回滚、手动提交
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