关于connect by的一个问题,请教高人!

CONNECT BY查询中有一个伪列叫LEVEL,表示一行纪录在树型结构中的层次,请看下例:
SQL> select * from t_tree
2 start with id='A'
3 connect by id= prior p_id;
ID P_ID
---------- ----------
A B
B S
S W
B D

SQL> select x.*, level from t_tree x
2 start with id='A'
3 connect by id=prior p_id;
ID P_ID LEVEL
---------- ---------- ----------
A B 1
B S 2
S W 3
B D 2

SQL> select x.*, level from t_tree x
2 where level < 3
3 start with id='A'
4 connect by id= prior p_id;
ID P_ID LEVEL
---------- ---------- ----------
A B 1
B S 2
B D 2

如果你看明白了,那问题应该就解决了.

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus