oracle查询树形关系

发表于: DB/ES | 作者: | 日期: 2008/11/24 12:11

Oracle用Start with…Connect By子句递归查询
Start with…Connect By子句递归查询一般用于一个表维护树形结构的应用。
创建示例表:
CREATE TABLE TBL_TEST
(
ID NUMBER,
NAME VARCHAR2(100 BYTE),
PID NUMBER DEFAULT 0
);

插入测试数据:
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES(‘1′,’10’,’0′);
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES(‘2′,’11’,’1′);
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES(‘3′,’20’,’0′);
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES(‘4′,’12’,’1′);
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES(‘5′,’121′,’2’);

从Root往树末梢递归
select * from TBL_TEST
start with id=1
connect by prior id = pid

从末梢往树ROOT递归
select * from TBL_TEST
start with id=5
connect by prior pid = id

参考:
http://blog.csdn.net/Caesar_Gu/archive/2008/01/21/2055985.aspx
http://oracle.chinaitlab.com/exploiture/734006.html
http://blog.sina.com.cn/s/blog_4bfad52101000b93.html
http://hi.baidu.com/suofang/blog/item/a58bdd5829d5e583800a1812.html

http://www.builder.com.cn/2007/1005/536404.shtml
http://deqiallen.javaeye.com/blog/92794

: https://blog.darkmi.com/2008/11/24/551.html

本文相关评论 - 1条评论都没有呢
Post a comment now » 本文目前不可评论

No comments yet.

Sorry, the comment form is closed at this time.