gpt4 book ai didi

MYSQL语法分隔符和语法错误

转载 作者:行者123 更新时间:2023-11-29 07:47:25 24 4
gpt4 key购买 nike

我尝试修复以下语法错误,但我看不出这里到底出了什么问题:

DELIMITER =
CREATE TRIGGER trigs BEFORE UPDATE ON autoinc
FOR EACH ROW BEGIN
DECLARE num_rows INTEGER;
SELECT (*) INTO num_rows FROM autoinc;
IF num_rows >=3 THEN
DELETE FROM autoinc LIMIT 1;
END IF;
END=
DELIMITER ;

错误是:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to          your MySQL server version for the right syntax to use near '*) INTO num_rows FROM autoinc; IF num_rows >' at line 4

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3 THEN

有人可以帮我解决这个问题吗?

最佳答案

正如评论中已经提到的:

SELECT (*) AS num_rows ...

可能本来就是

SELECT COUNT(*) AS num_rows ...

还有

IF num_rows >=3 THEN 

当您将 = 定义为分隔符时中断。

使用代码中未出现的分隔符,例如:

DELIMITER //

通过这两项更改,事情应该可以正常运行,而不会出现语法错误

关于MYSQL语法分隔符和语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27376058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com