我遇到了以下问题,我在存储过程中定义了一个变量(DOUBLE),我需要从表(项目)中为这个声明的变量分配一个值(项目价格)。但是,我需要从内部使用案例的选择查询中获取此值,根据我必须找到正确的商品价格的逻辑,商品价格可能在 2 列中。请帮我解决这个问题,因为当我执行它给我一个错误,
这里是如何分层的,
DECLARE no_more_users INT DEFAULT 0;
DECLARE user_id INT DEFAULT 0;
DECLARE cart_id INT DEFAULT 0;
DECLARE cart_item_id INT DEFAULT 0;
DECLARE user_gift_id INT DEFAULT 0;
DECLARE itemPrice DOUBLE DEFAULT 0.0;
SELECT
CASE
WHEN sale_price=0 OR sale_price IS NULL THEN (price - ( price * discount ))
ELSE sale_price
END
INTO itemPrice
FROM item WHERE item_id = p_item_id ;
DECLARE checked_in_users CURSOR FOR
SELECT DISTINCT ul.user_id
FROM user_location ul
LEFT JOIN location_section ls ON ul.location_section_id = ls.location_section_id
INNER JOIN user u ON ul.user_id = u.user_id
INNER JOIN user_profile up ON u.user_id = up.user_id
INNER JOIN location_event le ON ul.location_event_id = le.location_event_id
WHERE ul.location_id = p_location_id AND ul.location_event_id = p_event_id
AND ul.checked_out_on IS NULL AND (ul.checked_in_on BETWEEN le.start_time AND le.end_time )
AND u.status = 1 ;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET no_more_users = 1;
OPEN checked_in_users;
FETCH checked_in_users INTO user_id;
read_loop: LOOP
还有一些代码...
请注意,sale_price、price、discount 是 item 表的列,逻辑是如果 sale_price 为 null 或 value 为 0,那么我应该从 price 列中获取实际的销售价格。最后,我需要将正确的项目价格分配给先前声明的变量。任何帮助都将受到高度评价。