mysql GROUP_CONCAT

DELIMITER $$

USE `wf_workflow`$$

DROP FUNCTION IF EXISTS `getChildList`$$

CREATE DEFINER=`scadmin`@`%` FUNCTION `getChildList`(parentId VARCHAR (32)) RETURNS MEDIUMTEXT CHARSET utf8
BEGIN
DECLARE sTemp MEDIUMTEXT;
DECLARE iCount INT;
DECLARE sTempChd MEDIUMTEXT;
DECLARE sSeparator VARCHAR(32);
DECLARE sAllTempChd MEDIUMTEXT;
SET sTempChd = parentId;
SET iCount = 1;
SET sAllTempChd = CONCAT(parentId,';',iCount);
WHILE sTempChd IS NOT NULL DO
IF sTemp IS NULL THEN SET sTemp = sAllTempChd;
ELSE SET sTemp = CONCAT(sTemp, ',', sAllTempChd);
END IF;
SET iCount = iCount + 1;
SET sSeparator = CONCAT(';',iCount,',');
SELECT
GROUP_CONCAT(GroupId)
#,GROUP_CONCAT(GroupId)
#, GROUP_CONCAT(GroupId SEPARATOR sSeparator)
INTO sTempChd
#,sAllTempChd
FROM GROUP_GROUP
WHERE FIND_IN_SET(ParentGroupId, sTempChd) > 0;
SET sAllTempChd = CONCAT(REPLACE(sTempChd,',',sSeparator),';',iCount);
END WHILE;
RETURN sTemp;
END$$

DELIMITER ;

你可能感兴趣的:(group_concat)