Oracle树结构递归查询start with connect by prior的用法

SQL语句例子如下

select distinct id,name,TEST_TYPE,parentid 
from db_TEST t 
start with name='系统' connect by prior t.parentid= id
order by id

 查询出来的结果

 

1	0	default	0	
2	1	电子	0	0
3	401	CRM	0	1
4	541	CSM6	0	1
5	542	CSM8	0	1
6	543	ANS	0	1
7	544	SEMI	0	1
8	582	系统	0	401
9	588	系统	1	582
10	835	系统	0	541
11	841	系统	0	542
12	847	系统	0	543
13	853	系统	0	544
14	862	系统	1	835
15	863	系统	1	841
16	864	系统	1	847
17	865	系统	1	853

ORACLE中,name字段内容是'系统'的,递归调出他的上层父节点
t.parentid为子节点的父节点ID指向,

使用start with name='系统' connect by prior t.parentid= id

 

转载于:https://my.oschina.net/icelily/blog/79227

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值