Home  >  Article  >  Database  >  sql 函数-mysql创建函数一直提示语句错误

sql 函数-mysql创建函数一直提示语句错误

WBOY
WBOYOriginal
2016-06-06 09:43:031050browse

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

请问大神哪里有问题了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn