// 查询id为101的所有后代节点,包含101在内的各级父节点
select t.* from SYS_ORG t start with id = '101' connect by parent_id = prior id
2、查询某节点下所有后代节点(不包含各级父节点)
select t.*
from SYS_ORG t
where not exists (select 1 from SYS_ORG s where s.parent_id = t.id)
start with id = '101'
connect by parent_id = prior id
3、查询某节点所有父节点(所有祖宗节点)
select t.*
from SYS_ORG t
start with id = '401000501'
connect by prior parent_id = id
4、查询某节点所有的兄弟节点(亲兄弟)
select * from SYS_ORG t
where exists (select * from SYS_ORG s where t.parent_id=s.parent_id and s.id='401000501')
5、查询某节点所有同级节点(族节点),假设不设置级别字段
with tmp as(
select t.*, level leaf
from SYS_ORG t
start with t.parent_id = '0'
connect by t.parent_id = prior t.id)
select *
from tmp
where leaf = (select leaf from tmp where id = '401000501');
with tmp as(
select t.*, level lev
from SYS_ORG t
start with t.parent_id = '0'
connect by t.parent_id = prior t.id)
select b.*
from tmp b,(select *
from tmp
where id = '401000501' and lev = '2') a
where b.lev = '1'
union all
select *
from tmp
where parent_id = (select distinct x.id
from tmp x, --祖父
tmp y, --父亲
(select *
from tmp
where id = '401000501' and lev > '2') z --儿子
where y.id = z.parent_id and x.id = y.parent_id);