我正在尝试编译以下函数,但得到了很多语法错误。我犯了什么错误?我是不是遗漏了什么?我们能给出返回类型中字符的长度吗?
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毫秒)附近使用正确的语法。
发布于 2016-08-02 06:26:52
您必须为此定义一个delimiter:
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 ;https://stackoverflow.com/questions/38712109
复制相似问题