mysqlsql 函数循环查询
我在数据库的部门表里存的树形结构,在已知子部门时向上查找所有父级部门,写的函数如下
<code>CREATE FUNCTION queryAllDept(@currdeptid varchar(50))returns varchar(200)BEGIN declare @allname varchar(200) DEFAULT ''; declare @tempname varchar(200) DEFAULT ''; declare @tempparid varchar(200) DEFAULT ''; select @allname=`name`,@tempparid=parid from ym_dept where id=@currdeptid; while(@tempparid '0') do select @tempname=`name`,@tempparid=parid from ym_dept where id=@tempparid; set @allname=CONCAT(@tempname,',',@allname); end while; RETURN @allname;END</code>
错误提示:
[Err] 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 '@currdeptid varchar(50))
returns varchar(200)
BEGIN
declare @allname varchar' at line 1
请问大神哪里有问题了