从 Oracle 获取树/分层结构数据的最佳方法是什么
我想从具有以下定义的表中获取如下所示的分层/树数据。
Tree Table:
"""""""""""
Id |ParentId
"""""""""""
Work1|null
Work2|Work1
Work3|Work2
...
所需的查询结果数据(无需选项卡)- 如果我选择“Work1”,我应该完成位于其根目录下的 Id,如下所示。如果我选择“Work2”,那么我还应该填写其根目录上方和下方的 Id。
> Work1
----------
> Work2
----------
> Work3
---------
我使用了下面的查询,但它给了我重复的记录。
select Id from TreeTable start with Id in ('Work1','Work2') connect by nocycle Parentid=prior Id or Id = prior Parentid
注意:我想以单一查询(优化)方式获取数据
谢谢和问候, 光伏发电。
I want to fetch Hierarchical/Tree data something like below from a Table which has following definiton.
Tree Table:
"""""""""""
Id |ParentId
"""""""""""
Work1|null
Work2|Work1
Work3|Work2
...
Required Query result Data (no need to be tabbed)- If I Pick 'Work1' I should complete Ids which are under its root something like below. If I pick 'Work2' then also I should complete Ids above and below its root.
> Work1
----------
> Work2
----------
> Work3
---------
I used below query but it is giving me duplicate records.
select Id from TreeTable start with Id in ('Work1','Work2') connect by nocycle Parentid=prior Id or Id = prior Parentid
Note: I want to get the data within a SINGLE QUERY (optimized) way
Thanks and Regards,
PV.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此条件:
将切断已使用
START WITH
选择的分支。This condition:
will cut off the branches already selected with
START WITH
.