Oracle
select XXX from table
start with XXX
connect by prior XXX
Mysql(需要自己写)
1.先写一个 函数:
set global log_bin_trust_function_creators=TRUE;
DROP FUNCTION IF EXISTS `getChild`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `getChild`(pid VARCHAR(8000)) RETURNS varchar(8000) CHARSET utf8
COMMENT '获取所有孩子'
BEGIN
DECLARE sTemp VARCHAR(8000);
DECLARE sTempChd VARCHAR(8000);
SET sTemp='$';
SET sTempChd = pid;
WHILE sTempChd IS NOT NULL DO
SET sTemp= CONCAT(sTemp,',',sTempChd);
SELECT GROUP_CONCAT(id) INTO sTempChd FROM sys_organ WHERE del_flag='0' and FIND_IN_SET(parent_id,sTempChd)>0;
END WHILE;
RETURN sTemp;
END
;;
DELIMITER ;
2.FIND_IN_SET(id,getChild(“想要查找的父id”))