【问题标题】:A MySql function is not compiling and I cant find a reasonMySql 函数未编译,我找不到原因
【发布时间】:2015-09-20 07:18:31
【问题描述】:

您好,我通常是一个试图在 MySql 中尝试我的手的 oracle 人。我已经了解了基本概念,现在正在尝试开发功能。这样做时会遇到如下问题。 如果这是整个 Stackoverflow 中最愚蠢的问题,我深表歉意,但我无能为力 我的代码:

DELIMITER $$
CREATE FUNCTION test1 returns int (11)
begin
DECLARE id int(11) default 3;
return id;
end;
$$
delimiter ;

我在尝试创建上述函数时遇到以下错误

12:35:59 CREATE FUNCTION test1 返回 int (11) begin DECLARE myid int(11) default 3;返回myid;结尾;错误代码:1064。您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 '(11) begin DECLARE myid int(11) default 3; 附近使用正确的语法;返回myid;在第 1 行结束 0.000 秒

【问题讨论】:

    标签: mysql function mysql-error-1064


    【解决方案1】:

    您只是在函数名称后缺少 ():

    DELIMITER $$
    CREATE FUNCTION test1() RETURNS int(11)
    BEGIN
      DECLARE id int(11) DEFAULT 3;
      RETURN id;
    END;
    $$
    delimiter ;
    

    请看小提琴here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 2020-04-13
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 2022-11-24
      • 2020-08-31
      相关资源
      最近更新 更多