mysql - SQL IF ELSE 语句不执行

标签 mysql sql stored-procedures

我尝试为购物车创建以下准备好的语句,但它无法正确执行。它报告以下错误,我不知道如何修复它:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '; 附近使用的正确语法。第 25 行 END $$'

据我所知,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 $$

最佳答案

删除 END $$ 后面的 $$ 并在 END 和 IF 之间添加空格

    END IF;
    END $$

关于mysql - SQL IF ELSE 语句不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16791735/

相关文章:

php - 使用 INSERT 将整数值插入 mysql int

php - php项目运行时出现白屏

sql - 这个右连接问题的正确语法是什么?

sql - 如何使用 With 语句创建 View ?

mysql - 存储过程不存在,即使在创建之后

java - 如何在 hibernate 中调用程序?

日期字段上的 MySQL 索引

mysql - 使用 MVC Asp.net 删除 MySql 中的数据超时

sql - SQL 语句中不能使用分号。我该怎么办?

oracle - 在oracle中检查过程执行期间的错误