Mysql函数查询所有子节点


CREATE DEFINER=`root`@`%` FUNCTION `FN_GetOrgChild`(rootId INT) RETURNS longtext CHARSET utf8
    COMMENT '作者:coder7911 作用:获取部门节点子节点'
BEGIN 
		DECLARE sTemp LONGTEXT; 
		DECLARE sTempChd LONGTEXT; 
		SET sTemp = '$'; 
		SET sTempChd =cast(rootId as CHAR); 
		WHILE sTempChd is not null DO 
		SET sTemp = concat(sTemp,',',sTempChd); 
		SELECT group_concat(ORG_ID) INTO sTempChd FROM d_organization where  FIND_IN_SET(PARENT_ID,sTempChd)>0; 
		END WHILE; 
		RETURN sTemp; 
END


你可能感兴趣的:(数据库:mysql)