MySQL存储函数创建错误ERROR 1064和1327

前端之家收集整理的这篇文章主要介绍了MySQL存储函数创建错误ERROR 1064和1327前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用MySQL v5.1.36,我正在尝试使用此代码创建存储函数.

DELIMITER //
CREATE FUNCTION `modx`.getSTID (x VARCHAR(255)) RETURNS INT DETERMINISTIC
    BEGIN
    DECLARE y INT;
    SELECT id INTO y
    FROM `modx`.coverage_state
    WHERE `coverage_state`.name = x;
    RETURN y;
    END//

当进入MysqL控制台时,我得到了这个回复.

MysqL>  DELIMITER //
MysqL>  CREATE FUNCTION `modx`.getSTID (x VARCHAR(255)) RETURNS INT DETERMINISTIC
    ->          BEGIN
    ->          DECLARE y INT;
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 '' at
line 3
MysqL>          SELECT id INTO y
    ->          FROM `modx`.coverage_state
    ->          WHERE `coverage_state`.name = x;
ERROR 1327 (42000): Undeclared variable: y
MysqL>          RETURN y;
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 'RETUR
N y' at line 1
MysqL>          END//

从我在网上找到的我的语法是正确的.我究竟做错了什么?

最佳答案
MysqL控制台创建函数/过程时,第一个命令应该是DELIMITER //.否则,它使用默认分隔符(;),
原文链接:https://www.f2er.com/mysql/432853.html

猜你在找的MySQL相关文章