SQL function-a statement error is always prompted when you create a function in mysql.

Source: Internet
Author: User
I saved a tree structure in the department table of the database and looked up all parent departments when the sub-departments are known. the written function is as follows & quot; CREATEFUNCTIONqueryAllDept (@ currdeptidvarchar (50 )) returnsvarchar (200) BEGINdeclare @ allnamevarchar (200) DEFAULT & #39; & #39; declare @ tempnamevarchar (200) DEFAULT & #39; & #39 ;; declare @ tempparidvar mysqlsql function loop query

I have a tree structure in the department table of the database. when we know the sub-department, we can look up all parent departments. the written functions are as follows:

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

Error message:
[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

Where is the problem?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.