[英]Getting a MYSQL 1064 error when creating a function
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;
If I try to run this all I get is: 如果我尝试运行此命令,我将得到的是:
SQL Error (1064): You have an error in your SQL syntax;
SQL错误(1064):您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RETURN int
检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'RETURN int附近使用
BEGIN开始
DECLARE intOut INT;DECLARE intOut INT;
SET intOut = select count(' at line 2SET intOut =选择count('在第2行
A couple of changes to resolve the problem: 为解决该问题进行了一些更改:
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 ;
Defining the return type is done by the RETURNS
keywrod, not the RETURN
keyword: 定义返回类型是通过
RETURNS
键来完成的,而不是RETURN
关键字:
CREATE FUNCTION nameOfFunct(intIn int)
RETURNS int
BEGIN
DECLARE intOut INT;
SET intOut = SELECT count(*)
FROM tableToTakeFrom
WHERE columToCompareTo = intIn;
RETURN intOut;
END;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.