mysql 一个存储过程中执行第二个游标时候,则提示游标没有打开!
#打开之前定义的游标OPENC_WARRANTY;#loop_label:LOOP#IFno_more_departmentsTHEN#LEAVEloop_label;#...
#打开之前定义的游标
OPEN C_WARRANTY;
#loop_label: LOOP
#IF no_more_departments THEN
# LEAVE loop_label;
#END IF;
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO w_orderid, w_ordertime, w_member_id;
#循环语句的关键词
REPEAT
#调用流水号
CALL proc_serial_number(w_warranty_id);
SET no_more_departments=0;
#保修卡主表添加
CALL `proc_warranty`(w_warranty_id,w_orderid,w_ordertime,w_member_id);
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO w_orderid, w_ordertime, w_member_id;
#循环语句结束
UNTIL no_more_departments END REPEAT;
#END LOOP;
#关闭游标
CLOSE C_WARRANTY;
SET no_more_departments = 0;
#打开明细游标
OPEN C_WARRANTY_DETAIL;
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO wd_warranty_id, wd_item_id, wd_order_id,wd_obj_id,wd_product_id,
wd_goods_id,wd_type_id,wd_bn,wd_pn,wd_name,wd_nums,wd_sendnum,wd_addon,wd_item_type;
#循环语句的关键词
REPEAT
#生成保修卡明细
CALL `proc_warranty_detail`(wd_warranty_id, wd_item_id, wd_order_id,wd_obj_id,wd_product_id,
wd_goods_id,wd_type_id,wd_bn,wd_pn,wd_name,wd_nums,wd_sendnum,wd_addon,wd_item_type);
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO wd_warranty_id, wd_item_id, wd_order_id,wd_obj_id,wd_product_id,
wd_goods_id,wd_type_id,wd_bn,wd_pn,wd_name,wd_nums,wd_sendnum,wd_addon,wd_item_type;
#循环语句结束
UNTIL no_more_departments END REPEAT;
CLOSE C_WARRANTY_DETAIL; 展开
OPEN C_WARRANTY;
#loop_label: LOOP
#IF no_more_departments THEN
# LEAVE loop_label;
#END IF;
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO w_orderid, w_ordertime, w_member_id;
#循环语句的关键词
REPEAT
#调用流水号
CALL proc_serial_number(w_warranty_id);
SET no_more_departments=0;
#保修卡主表添加
CALL `proc_warranty`(w_warranty_id,w_orderid,w_ordertime,w_member_id);
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO w_orderid, w_ordertime, w_member_id;
#循环语句结束
UNTIL no_more_departments END REPEAT;
#END LOOP;
#关闭游标
CLOSE C_WARRANTY;
SET no_more_departments = 0;
#打开明细游标
OPEN C_WARRANTY_DETAIL;
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO wd_warranty_id, wd_item_id, wd_order_id,wd_obj_id,wd_product_id,
wd_goods_id,wd_type_id,wd_bn,wd_pn,wd_name,wd_nums,wd_sendnum,wd_addon,wd_item_type;
#循环语句的关键词
REPEAT
#生成保修卡明细
CALL `proc_warranty_detail`(wd_warranty_id, wd_item_id, wd_order_id,wd_obj_id,wd_product_id,
wd_goods_id,wd_type_id,wd_bn,wd_pn,wd_name,wd_nums,wd_sendnum,wd_addon,wd_item_type);
#取出每条记录并赋值给相关变量,注意顺序
FETCH C_WARRANTY INTO wd_warranty_id, wd_item_id, wd_order_id,wd_obj_id,wd_product_id,
wd_goods_id,wd_type_id,wd_bn,wd_pn,wd_name,wd_nums,wd_sendnum,wd_addon,wd_item_type;
#循环语句结束
UNTIL no_more_departments END REPEAT;
CLOSE C_WARRANTY_DETAIL; 展开
1个回答
2015-03-19
展开全部
DECLARE stuName VARCHAR(50);
DECLARE flag INT;
DECLARE update_cursor CURSOR
FOR
SELECT stu_name FROM student WHERE id = id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1;
SET flag=0;
OPEN update_cursor;
REPEAT /*循环*/
FETCH update_cursor INTO stuName;
SET json = CONCAT(json,',',stuName);
UNTIL flag
END REPEAT;
CLOSE update_cursor ;
DECLARE flag INT;
DECLARE update_cursor CURSOR
FOR
SELECT stu_name FROM student WHERE id = id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1;
SET flag=0;
OPEN update_cursor;
REPEAT /*循环*/
FETCH update_cursor INTO stuName;
SET json = CONCAT(json,',',stuName);
UNTIL flag
END REPEAT;
CLOSE update_cursor ;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询