Oracle 递归查询

 1 select a.accountcodeid, a.accountcode, a.accountcodename,
 2        SYS_CONNECT_BY_PATH(a.accountcodename, '\') as fullname, a.parentcodeid, level
 3   from fm_accountcode a
 4  where a.accountcodeid >= 10000
 5  start with a.parentcodeid is null
 6 connect by prior a.accountcodeid = a.parentcodeid;
 7 
 8 select a.accountcodeid, a.accountcode, a.accountcodename,
 9        SYS_CONNECT_BY_PATH(a.accountcodename, '\') as fullname,
10        a.parentcodeid
11   from fm_accountcode a
12  where a.accountcodeid > 10000
13    and connect_by_isleaf = 1
14  start with a.parentcodeid is null
15 connect by prior a.accountcodeid = a.parentcodeid;

oracle 中递归查询,对树型结构数据相当有用。

二者区别:上,所有数据,包含结构;下,所有末节点,包含结构,具体参见Oracle Document 11g。

posted @ 2015-09-01 21:27  怎样疯狂的涛涛  阅读(462)  评论(0编辑  收藏  举报