这是我的代码。我正在尝试将购物车项目移动到订单商品表中。什么可能是错误的它不起作用?
CREATE PROCEDURE `insert_order_details`
(IN `customer_id` VARCHAR(255),
IN `order_id` VARCHAR(255),
IN `shipping_country` VARCHAR(255),
IN `shipping_state` VARCHAR(255),
IN `shipping_address` VARCHAR(255))
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE product_id varchar(255);
DECLARE quantity integer;
DECLARE unit_price integer;
Declare cart_cursor CURSOR
FOR select @order_id, product_id , quantity, unit_price, userID
from cart where userID=@customer_id and status = 'PENDING';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
OPEN cart_cursor;
read_loop: LOOP
FETCH cart_cursor INTO order_id, product_id, quantity, unit_price, customer_id;
IF v_finished = 1 THEN
LEAVE read_loop;
END IF;
INSERT INTO order_details
(order_id,product_id, quantity, unit_price,
customer_id,shipping_country,shippping_state, shipping_address)
VALUES
(@order_id,product_id, quantity, unit_price, @customer_id,
date_added,@shipping_country,@shipping_state,@shipping_address) ;
END LOOP read_loop;
CLOSE cart_cursor;
END
答案 0 :(得分:0)
您在光标中引用了用户变量@order_id,而实际上您想要使用存储过程变量order_id。