Mysql 尝试编译函数时出现语法错误
我试图编译下面的函数,但是得到了很多语法错误。我犯了什么错误?我错过什么了吗?我们能给出返回类型中字符的长度吗Mysql 尝试编译函数时出现语法错误,mysql,function,stored-functions,Mysql,Function,Stored Functions,我试图编译下面的函数,但是得到了很多语法错误。我犯了什么错误?我错过什么了吗?我们能给出返回类型中字符的长度吗 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 g
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,则使用near'的语法
在第5行设置invoiceId=concat('QUA-',lpad(id,7')(0毫秒)
错误代码:1064您的SQL语法有错误;请检查
与右边的MySQL服务器版本相对应的手册
在第1行使用接近“end if”的语法(0毫秒)
错误代码:1064您的SQL语法有错误;请检查
与右边的MySQL服务器版本相对应的手册
第1行“return invoiceId”附近使用的语法(0毫秒)
错误代码:1064您的SQL语法有错误;请检查
与右边的MySQL服务器版本相对应的手册
第1行“结束”附近使用的语法(0毫秒)
您必须为此定义一个
分隔符
:
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 ;
您是否正在使用任何客户端,比如Workbench,或者只是在MySQL的终端模式接口中键入函数创建?@FDavidov
SQLYog
对不起,我不知道。我唯一想到的是,在使用终端模式时,您需要用分隔符
语句包装过程/函数创建(我不知道这是否与SQLYog有关)。很抱歉,我帮不了你更多的忙。