通过connect检索父级和子级

时间:2017-06-23 08:16:38

标签: sql database oracle oracle11g

我有以下查询:

var confirm = document.getElementsByClassName("indexy")[0].hasChildNodes();

此查询为ID为6的父级带来所有子级。我的问题是,是否有可能返回ID为6的父级子节点以及同一结果集中的父级子节点的查询。

1 个答案:

答案 0 :(得分:1)

我同意Boneist - START WITH child_id = 6可以解决问题 见下面的样本

with ORGANIZATION_TABLE as
(select 1 as parent_id, 0 as child_id from dual union all
 select null as parent_id, 6 as child_id from dual union all
 select 6 as parent_id, 61 as child_id from dual union all
 select 6 as parent_id, 62 as child_id from dual union all
 select 6 as parent_id, 63 as child_id from dual union all
 select 63 as parent_id, 631 as child_id from dual union all
 select 63 as parent_id, 632 as child_id from dual union all
 select 631 as parent_id, 6311 as child_id from dual union all
 select 7 as parent_id, 0 as child_id from dual 
) 
SELECT *
  FROM ORGANIZATION_TABLE
  START WITH child_id       = 6
  CONNECT BY PRIOR   CHILD_ID = PARENT_ID;


1       6
2   6   61
3   6   62
4   6   63
5   63  631
6   631 6311
7   63  632