mysql游标 循环_MySQL游标循环问题?

写了一个存储过程,代码如下,作用是将模块表和用户表中的模块id和用户id都查询出来,然后逐一匹配写入user_module表中,但是执行结果确实,只写入了一个用户的数据,其他的用户都没有,这是什么情况呢?

create procedure in_do()

begin

declare moid,puid int;

declare do1,do2 int default false;

declare attr_1 cursor for select id from user_public;

declare attr_2 cursor for select id from public_module where status='1' and (pid!=0 or special='1');

declare continue handler for not found set do1=true;

open attr_1;

read_loop:loop

fetch attr_1 into puid;

if do1 then

leave read_loop;

end if;

begin

declare continue handler for not found set do2=true;

open attr_2;

read_loop1:loop

fetch attr_2 into moid;

if do2 then

leave read_loop1;

end if;

insert into user_module(public_id,module_id,stime,etime) values(puid,moid,'1483203661','1514739661');

end loop;

close attr_2;

end;

end loop;

close attr_1;

end //

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值