首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在编译函数时获取语法错误

在编译函数时获取语法错误
EN

Stack Overflow用户
提问于 2016-08-02 05:03:56
回答 1查看 37关注 0票数 2

我正在尝试编译以下函数,但得到了很多语法错误。我犯了什么错误?我是不是遗漏了什么?我们能给出返回类型中字符的长度吗?

代码语言:javascript
复制
create function generate_invoice_number(id int) returns varchar(11)
    deterministic 
begin
    declare invoiceId varchar(11) default null;
    /**
         * Here id refers to the ID that is generated in the 
     * invoice table.
     */
    if id is not null and id > 0 
        then
            set invoiceId = concat('QUA-',lpad(id,7,'0'));
    end if;

    return invoiceId;
end;

错误:

错误代码: 1064您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在第4行(取0毫秒)附近使用正确的语法。 错误代码: 1064您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以获得在“如果id不为null且id >0”附近使用的正确语法,然后设置invoiceId = concat('QUA-',lpad(id,7 ),在第5行(0 ms ))。 错误代码: 1064您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以获得在第1行(取0 ms )附近使用“end if”的正确语法。 错误代码: 1064您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以获得在第1行(取0毫秒)附近使用“返回invoiceId”的正确语法。 错误代码: 1064您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以便在第1行(取0毫秒)附近使用正确的语法。

EN

回答 1

Stack Overflow用户

发布于 2016-08-02 06:26:52

您必须为此定义一个delimiter

代码语言:javascript
复制
delimiter $$

create function generate_invoice_number(id int) returns varchar(11)
    deterministic 
begin
    declare invoiceId varchar(11) default null;
    /**
         * Here id refers to the ID that is generated in the 
     * invoice table.
     */
    if id is not null and id > 0 
        then
            set invoiceId = concat('QUA-',lpad(id,7,'0'));
    end if;

    return invoiceId;
end$$

delimiter ;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38712109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档