【发布时间】:2018-05-12 05:33:18
【问题描述】:
我已经在 mysql 存储过程中实现了 CURSOR...我在读取游标时遇到了挑战...基本上我想从游标中读取列值并将其存储到变量中..但我得到了变量值为NULL...解决方案是什么...请帮助我..提前致谢...
我的代码如下,
delimiter //
CREATE PROCEDURE placeOrder(IN cartId INT)
BEGIN
DECLARE countitem INT DEFAULT 0;
DECLARE productId INT;
DECLARE quantity INT;
DECLARE itemDicountAmt DOUBLE DEFAULT 0;
DECLARE v_finished INT DEFAULT 0;
DEClARE cart_cursor CURSOR FOR
SELECT ProductId, Quantity FROM TBL_SHOPPING_CART_ITEM;
-- declare NOT FOUND handler
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;
OPEN cart_cursor;
get_cart: LOOP
FETCH cart_cursor into productId, quantity;
IF v_finished = 1 THEN
LEAVE get_cart;
END IF;
-- build email list
insert into debugtable select concat('PRODUCT :', productId);
insert into debugtable select concat('QUANTITY :', quantity);
END LOOP get_cart;
CLOSE cart_cursor;
END//
delimiter ;
输出:
tmptable 无效的 空
因为我的购物车表中有一条记录...
【问题讨论】:
标签: mysql stored-procedures database-cursor