给出一个简单的(ID,描述)表t1,如在Oracle树加入其他表的查询
id description
-- -----------
1 Alice
2 Bob
3 Carol
4 David
5 Erica
6 Fred
而且父子关系表T2,如
parent child
------ -----
1 2
1 3
4 5
5 6
Oracle提供一种将其作为具有一些自定义语法扩展的树遍历的方式:
select parent, child, sys_connect_by_path(child, '/') as "path"
from t2
connect by prior parent = child
确切的语法并不重要,我在上面可能犯了一个错误。该 重要的是,上面会产生一些看起来像
parent child path
------ ----- ----
1 2 /1/2
1 3 /1/3
4 5 /4/5
4 6 /4/5/6
5 6 /5/6
我的问题是:是否有可能加入SYS_CONNECT_BY_PATH()内的另一个表,如表T1以上,产生类似:
parent child path
------ ----- ----
1 2 /Alice/Bob
1 3 /Alice/Carol
... and so on...
换句话说,使用派生表。当然!好戏。 – dland 2008-09-23 07:57:09