假设有表test_1:
BEGIN
DECLARE err int DEFAULT 0;
declare continue handler for sqlexception set err=1;#当sqlexception handler捕捉到异常时,设置err=1
START TRANSACTION;#开始事务
update test_1 set value = 50 where id = 58;
IF (err=0) THEN
commit;#增加;否则会报错
select 1;#增加;否则会报错
ELSE
rollback;#增加;否则会报错
select 0;#增加;否则会报错
END IF;#增加;否则会报错
END
执行结果为:
test_1表更新为: