MySql 存储过程遍历游标出错 10
存储过程如下createprocedureproc_demo1()BEGINdeclarev_userIdbigint;declarev_moneybigint;decl...
存储过程如下
create procedure proc_demo1()
BEGIN
declare v_userId bigint;
declare v_money bigint;
declare cur_luck_draw CURSOR for select a.user_id,a.money from aug_activity_luck_draw a ;
declare exit HANDLER for not found close cur_luck_draw;
START TRANSACTION;
open cur_luck_draw;
repeat
fetch cur_luck_draw into v_userId,v_money;
INSERT INTO aug_activity_luck_draw(user_id,money,frequency,draw_time) VALUES (v_userId, v_money, 1, now());
until 0 end repeat;
close cur_luck_draw;
commit;
END $$
调用之前,activity_luck_draw有3条记录,第一次调用时没有数据,第二次调用时多了18条,是不是游标有问题 展开
create procedure proc_demo1()
BEGIN
declare v_userId bigint;
declare v_money bigint;
declare cur_luck_draw CURSOR for select a.user_id,a.money from aug_activity_luck_draw a ;
declare exit HANDLER for not found close cur_luck_draw;
START TRANSACTION;
open cur_luck_draw;
repeat
fetch cur_luck_draw into v_userId,v_money;
INSERT INTO aug_activity_luck_draw(user_id,money,frequency,draw_time) VALUES (v_userId, v_money, 1, now());
until 0 end repeat;
close cur_luck_draw;
commit;
END $$
调用之前,activity_luck_draw有3条记录,第一次调用时没有数据,第二次调用时多了18条,是不是游标有问题 展开
1个回答
2017-08-19
展开全部
MySql 存储过程遍历游标出错
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET DONE = 1;
这种语句是异常捕获内容,在mysql中都是使用HANDLER 来捕获异常的。
建议你看下:MySQL存储过程详解
MySQL游标循环遍历的使用
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET DONE = 1;
这种语句是异常捕获内容,在mysql中都是使用HANDLER 来捕获异常的。
建议你看下:MySQL存储过程详解
MySQL游标循环遍历的使用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询