有关于MYSQL回滚的存储过程问题

发布于 2021-11-14 09:46:07 字数 1316 浏览 886 评论 4

BEGIN
	DECLARE t_error INTEGER DEFAULT 0;
	DECLARE CONTINUE HANDLER FOR 1062 SET t_error=1;
	set autocommit=0;
	START TRANSACTION;
	call put_playerbehavior(i_playerid,i_gameid,i_channelid,i_acttime,@a);
	IF t_error=1 then
		rollback;
		call  put_playerbehavior(i_playerid,i_gameid,i_channelid,i_acttime,@a);
	END IF;
	COMMIT;
END
begin
 DECLARE v_playerid int;
 DECLARE v_gameid int;
 DECLARE v_channelid int;
 DECLARE done int;
 DECLARE v_acttime datetime;
 DECLARE v_endday datetime;
 DECLARE cur_behavior CURSOR FOR select playerid,gameid,channelid,acttime from playerbehavior where acttime >= i_startday and acttime <  date_add(i_endday,INTERVAL 1 day);
 declare continue handler FOR SQLSTATE '02000' SET done = 1;


 set o_out=0;
 set v_endday=date_add(i_endday,INTERVAL 1 day);


 open cur_behavior;
 repeat
 FETCH  cur_behavior INTO v_playerid,v_gameid,v_channelid,v_acttime;
 CALL test_roll(v_playerid,v_gameid,v_channelid,v_acttime,@a);
 until done end repeat;
 close cur_behavior;
 set o_out=1;
end
第二个存储过程调用第一个存储过程,功能是把playerbehavior表中符合条件的数据用test_roll存储过程进行分析处理,讲结果放到一张表中,但是实际运行过程中,符合条件的最后一条数据会重复运行一次,不知道是什么情况~求大神解惑~分析的存储过程是没错的,就是以上2个存储过程~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

命硬 2021-11-19 06:46:30

谢谢~~那有什么办法能解决么~

裸钻 2021-11-19 06:46:15
FETCH  之后会触发handler进行SET done = 1;

但FETCH 与 until中间的代码会继续执行,从而引起最后一条数据被重复运行

无法言说的痛 2021-11-19 03:33:21

大神,膜拜一下

清晨说ぺ晚安 2021-11-18 20:05:36

rp_1:repeat

    fetch cur** into **;

    if  done=1 then

        leave rp_1;

    end if;

    call procedure(********);

until  done end repeat rp_1:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文