mysql查询树状目录所有子节点
DELIMITER // CREATE FUNCTION `getChildLst`(rootId INT) RETURNS VARCHAR(1000) BEGIN DECLARE sTemp VARCHAR(1000); DECLARE sTempChd VARCHAR(1000); SET sTemp = '$'; SET sTempChd =CAST(rootId AS CHAR); WHILE sTempChd IS NOT NULL DO SET sTemp = CONCAT(sTemp,',',sTempChd); SELECT GROUP_CONCAT(ID_DIRECTORY) INTO sTempChd FROM r_directory WHERE FIND_IN_SET(ID_DIRECTORY_PARENT,sTempChd)>0; END WHILE; RETURN sTemp; END // SELECT * FROM r_directory WHERE FIND_IN_SET(ID_DIRECTORY, getChildLst(1));