【发布时间】:2016-10-30 19:18:24
【问题描述】:
问题很清楚,但我已经尝试了很多方法来解决它,包括使用与表字段不同的变量名。从游标中获取的值总是返回 null。分配给游标提取的值是相同的数据类型 (int(11))。我正在做的是将从游标的选择表中提取的 key_id 值分配给 @my_key_id int(11) 变量,但它一直为空。
declare my_key_id int(11); /*variable that will be assigned from the value in cursor*/
DECLARE done INT DEFAULT FALSE; /*for cursor break*/
DECLARE cr_cursor cursor for select key_id from tmp_valuesss; /*cursor declaration*/
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; /*break thingy*/
open cr_cursor;
read_loop: LOOP
IF done THEN
LEAVE read_loop;
END IF;
select @my_key_id;
FETCH cr_cursor INTO my_key_id;
END LOOP;
close cr_cursor;
【问题讨论】:
-
如果 Drew 的帖子回答了您的问题,您应该接受答案,而不是删除您的问题。
-
我的错误,不是要删除的意思。
-
@MeinHat 如果您在存储过程中遇到问题或相关问题,请随时在Campaigns 房间与我聊天,我们可以解决。
-
如果您有其他问题,最好ask a new question 而不是继续编辑这个问题。
标签: mysql loops stored-procedures cursor