DELIMITER $$


DROP FUNCTION IF EXISTS getChildCat$$

CREATE  FUNCTION getChildCat(catId VARCHAR(10000)) RETURNS VARCHAR(4000) CHARSET utf8
BEGIN
DECLARE sTemp VARCHAR(4000);
DECLARE sTempChd VARCHAR(4000);
SET sTemp = '$';
SET sTempChd = catId;
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 ;