mysql存储过程游标结果集时,数据没有遍历完整
mysql存储过程游标结果集时,里面调用其他存储过程,如果调用的存储过程查询为空,游标循环就结束了,怎么解决...
mysql存储过程游标结果集时,里面调用其他存储过程,如果调用的存储过程查询为空,游标循环就结束了,怎么解决
展开
1个回答
展开全部
CREATE DEFINER=`root`@`%` PROCEDURE `insertPresale`()
BEGIN
#Routine body goes here...
DECLARE done INT DEFAULT 0; /*用于判断是否结束循环*/
DECLARE goodsId VARCHAR(255);#标记商品id
DECLARE flag INT DEFAULT 0;#标记数据库是否包含此条商品记录
/*用于存储结果集的记录*/
/*定义游标*/
DECLARE idCur CURSOR FOR SELECT goods_id FROM `sys_goods_publish` WHERE presale= 1 AND presale_time <= NOW();
/*定义 设置循环结束标识done值怎么改变 的逻辑*/
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; /*done = true;亦可*/
OPEN idCur; /*打开游标*/
/* 循环开始 */
REPEAT
#/* 如果要fetch多列应该这样写,fetch cur/*对应下面的idCur*/
FETCH idCur INTO goodsId; /*还可以fetch多列(假设结果集的记录不是单列的话)*/
IF NOT done THEN /*数值为非0,MySQL认为是true*/
SELECT COUNT(*) INTO flag FROM `itemsinfonew` WHERE TaoBaoitemId = goodsId;
IF (flag>0) THEN #如果数据库中有爬取此条记录则删除已用户发布的为准
DELETE FROM `itemsinfonew` WHERE TaoBaoitemId = goodsId;
END IF;
INSERT INTO `itemsinfonew` (TaoBaoitemId,CouponID,CreateSourceName)
SELECT goods_id,coupon_id,SUBSTRING("customer_fd",0.5)
FROM `sys_goods_publish`
WHERE presale_time <= NOW() AND goods_id = goodsId;
UPDATE `sys_goods_publish` SET presale = 0 WHERE presale= 1 AND presale_time <= NOW() AND goods_id = goodsId;
END IF;
UNTIL done END REPEAT;
CLOSE idCur; /*关闭游标*/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询