DELIMITER $$


DROP FUNCTION IF EXISTS `getCatelist`$$

CREATE FUNCTION `getCatelist`(branchId VARCHAR(10000)) RETURNS VARCHAR(4000) CHARSET utf8
BEGIN
DECLARE sTemp VARCHAR(4000);
DECLARE sTempChd VARCHAR(4000);
SET sTemp = '$';
SET sTempChd = branchId;
WHILE sTempChd IS NOT NULL DO
SET sTemp = CONCAT(sTemp,',',sTempChd);
SELECT GROUP_CONCAT(cat_code) INTO sTempChd FROM hc_category_inf WHERE FIND_IN_SET(CAT_PARENT_CODE,sTempChd)>0;
END WHILE;
RETURN sTemp;
END$$

DELIMITER ;