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.