Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-06 09:43:03
Original
1055 people have browsed it

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>
Copy after login

错误提示:
[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

请问大神哪里有问题了

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!