Note the following when assigning values to mysql variables:

Source: Internet
Author: User

Note that mysqlsql needs to write a stored procedure for the project today, which is rare once a year. So there is no way to pick it up again. Start writing to later ..

SQL code CREATE FUNCTION 'getchildlstnotsun' (department_id int) RETURNS varchar (1000) BEGIN DECLARE sTemp VARCHAR (1000); DECLARE sTempChd int; declare fetchSeqOk boolean; declare cur1 cursor for select partition mentid FROM partition where partition = department_id; declare continue handler for not found set Partition = true; SET Partition = false; OPEN cur1; fetchSeqLoop: Loop FETCH cur1 INTO sTempChd; if fetchSeqOk then leave fetchSeqLoop; else SET sTemp: = concat (sTemp, ',', sTempChd); end if; end loop; CLOSE cur1; RETURN sTemp; END

 

Code similar to for loop String concatenation is required
SQL code OPEN cur1; fetchSeqLoop: Loop FETCH cur1 INTO sTempChd; if fetchSeqOk then leave fetchSeqLoop; else SET sTemp: = concat (sTemp, ',', sTempChd); end if; end loop; CLOSE cur1;

 

After debugging for half a day, the sTemp variable cannot be found. The result is SET fetchSeqOk = false, followed by set sTemp =. Nima, it turns out that this requires initialization. By the way, it is best to use the group_concat function of mysql only on string fields.

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.