gpt4 book ai didi

mysql - 创建函数时出现 MYSQL 1064 错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:28 25 4
gpt4 key购买 nike

DELIMITER $$

CREATE FUNCTION nameOfFunct(intIn int)
RETURN int
BEGIN
DECLARE intOut INT;
SET intOut = SELECT count(*)
FROM tableToTakeFrom
WHERE columToCompareTo = intIn;

RETURN intOut;
END;
$$

DELIMITER;

如果我尝试运行它,我得到的是:

SQL Error (1064): 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 'RETURN int
BEGIN
DECLARE intOut INT;
SET intOut = select count(' at line 2

最佳答案

解决问题的几个更改:

DELIMITER $$

CREATE FUNCTION nameOfFunct(intIn INT)
-- RETURN INT
RETURNS INT
BEGIN
DECLARE intOut INT;
/*SET intOut = SELECT COUNT(*)
FROM tableToTakeFrom
WHERE columToCompareTo = intIn;*/
SET intOut = (SELECT COUNT(*)
FROM tableToTakeFrom
WHERE columToCompareTo = intIn);
RETURN intOut;
END $$

DELIMITER ;

关于mysql - 创建函数时出现 MYSQL 1064 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19742002/

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