Oracle Connect by SQL查询 [英] Oracle Connect By SQL Query

查看:58
本文介绍了Oracle Connect by SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我想带所有的孩子,包括使用parentid的parent,这是怎么回事.通过循环用户数据获取Exception连接. 预先感谢.

Here I want to take all the children including parent using parentid what is wrong.Am getting Exception connect by in loop user data. Thanks in Advance.

查询:

  select *
  from rdt_organization 
  connect by prior parentid = 102;

表格内容:

id  parentid  
102 null
103 102
112 102
104 103
105 null
106 105

预期输出:

id  parentid  
102 null
103 102
112 102
104 103

推荐答案

您需要使用id和parentid将行连接到PRIOR行,并使用START WITH决定从哪里开始;

You need to connect the rows to the PRIOR row using id and parentid, and use START WITH to decide where to start;

SELECT * 
FROM rdt_organization
START WITH id = 102
CONNECT BY PRIOR id = parentid

要测试的SQLfiddle .

这篇关于Oracle Connect by SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆