樹形查詢

jss001發表於2009-02-08
create table test(
bm number(8),
bmmc varchar2(20),
sjbm number(8)
);

insert into test values(1,'aaa',0);
insert into test values(11,'aaa1',1);
insert into test values(12,'aaa2',1);
insert into test values(111,'aaa11',11);
insert into test values(112,'aaa12',11);
insert into test values(113,'aaa13',11);
insert into test values(121,'aaa21',12);
insert into test values(122,'aaa22',12);
insert into test values(123,'aaa23',12);
--
select bm,bmmc,sjbm,level
from zj
start with sjbm=0
connect by prior bm = sjbm;
或者

select bm,bmmc,sjbm,level
from zj
start with sjbm=0
connect by sjbm = prior bm;[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18921899/viewspace-1016951/,如需轉載,請註明出處,否則將追究法律責任。

相關文章