我试着为我的购物车创建以下准备好的语句,但它无法正确执行。它报告以下错误,我不知道如何解决它:SQL IF ELSE语句不执行
#1064 - 您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以找到在';'附近使用的正确语法。 END $$'在第25行
据我所知IF语句语法是正确的,但它只是不会工作。
DELIMITER $$
CREATE PROCEDURE shopping_cart_add_product(IN inCartId CHAR(32),
IN inProductId INT, IN inAttributes VARCHAR(1000))
BEGIN
DECLARE productQuantity INT;
SELECT quantity
FROM shopping_cart
WHERE cart_id = inCartId
AND product_id = inProductId
AND attributes = inAttributes
INTO productQuantity;
IF productQuantity IS NULL THEN
INSERT INTO shopping_cart(cart_id, product_id, attributes,
productQuantityuantity, added_on)
VALUES (inCartId, inProductId, inAttributes, 1, NOW());
ELSE
UPDATE shopping_cart
SET quantity = quantity + 1, buy_now = true
WHERE cart_id = inCartId
AND product_id = inProductId
AND attributes = inAttributes;
ENDIF;
END $$
宾果游戏!我不能相信我错过了那些,我以为我试过了最后两行的每一个变化。谢谢 – useyourillusiontoo