简体   繁体   English

MySQL错误1064存储过程错误

[英]Mysql error 1064 stored procedure error

create function sf_get_empsallist(dname varchar(100))
returns varchar(300)
begin
declare emplist varchar(300) default '';
declare flag int default 0 ;
declare name varchar(100);
declare sal int;
declare c1 cursor  for
select ename,salary from emp join dept
on emp.deptid=dept.deptid
where deptname=dname;
declare continue handler for not found set flag=1;
open c1;
myloop: loop
fetch c1 into name,sal;
if flag=1 then
leave myloop;
end if;
set emplist=concat(emplist,',',name,'-',sal);
end loop;
return(substr(emplist,2));
close c1;
end
$$

The error im getting is 我得到的错误是

 Error Code: 1064. 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 4 

I tried by best at getting it solved but couldn't find it. 我尽最大努力解决了问题,但找不到。

delimiter $$
SET GLOBAL log_bin_trust_function_creators = 1;
create function sf_get_empsallist(dname varchar(100))
returns varchar(300)
begin
declare emplist varchar(300) default '';
declare flag int default 0 ;
declare name varchar(100);
declare sal int;
declare c1 cursor  for
select ename,salary from emp join dept
on emp.deptid=dept.deptid
where deptname=dname;
declare continue handler for not found set flag=1;
open c1;
myloop: loop
fetch c1 into name,sal;
if flag=1 then
leave myloop;
end if;
set emplist=concat(emplist,',',name,'-',sal);
end loop;
return(substr(emplist,2));
close c1;
end
$$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM