mysql存储过程问题

wbc_18989265729 2018-10-11 02:18:14
存储过程A 起事务 成功提交 失败回滚

A 中调用存储过程 B B失败了。A的不能回滚。。。怎么能处理?求大神告知
...全文
212 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wbc_18989265729 2018-10-11
  • 打赏
  • 举报
回复

BEGIN

declare v_err_param varchar(1024);
DECLARE V_ERR_NO INT DEFAULT 0;
declare v_sp_name varchar(64) default '';
declare v_row int;
declare v_done int DEFAULT 0;

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET V_ERR_NO=1;



SET V_ERR_NO=-1;
set v_sp_name='xxxxx';


sp_context:begin

start transaction;

INSERT INTO tttb1 (is_ok) VALUES ('ok1-1');
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;
if '0000'=p_bfflag then
call sp_2();
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;
if 1=1 THEN
zcbfloop: LOOP

INSERT INTO tttb3 (is_ok) VALUES ('ok3-1');
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;
begin
INSERT INTO tttb1 (is_ok) VALUES ('ok1-2');
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;

loop_room:loop
call sp_2();
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;
end loop;
end;


set v_done=0;

end loop;

ELSE
tkloop: LOOP

INSERT INTO tttb3 (is_ok) VALUES ('ok3-2');
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;
set v_done=0;

end loop;

end if;

INSERT INTO tttb1 (is_ok) VALUES ('ok1-3');
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;

ELSE

call sp_2();
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;
end if;

INSERT INTO tttb3 (is_ok) VALUES ('ok3-3');
if V_ERR_NO=1 THEN
set v_row=159;
leave sp_context;
end if;

commit;
end sp_context;


if V_ERR_NO=1 THEN
rollback;
end if;

END


loop_room:loop下面的sp_2() 出错了,但是外面的也执行了。造成数据不一致。循环操作的
卖水果的net 2018-10-11
  • 打赏
  • 举报
回复
存储过程中,是否包含 commit 语句。 如果存储过程不长的话,可以把语句贴上来。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧