DROP FUNCTION IF EXISTS queryChildOrgList;
CREATE FUNCTION queryChildOrgList(id VARCHAR(20))
RETURNS VARCHAR(2000)
BEGIN
DECLARE sTemp VARCHAR(2000) DEFAULT '';
DECLARE displayIds VARCHAR(1000) DEFAULT '';
DECLARE currParentIds VARCHAR(1000) DEFAULT '';
SET sTemp=id;
SET currParentIds=id;
SET displayIds='';
WHILE displayIds IS NOT NULL DO
SET sTemp = CONCAT(sTemp,',',displayIds);
select GROUP_CONCAT(display_id) into displayIds from agent where FIND_IN_SET(parent_id,currParentIds)>0;
SET currParentIds = displayIds;
END WHILE;
RETURN sTemp;
END;