简体   繁体   English

Oracle Connect通过SQL查询

[英]Oracle Connect By SQL Query

Here I want to take all the children including parent using parentid what is wrong.Am getting Exception connect by in loop user data. 在这里,我想带所有的孩子,包括使用parentid的parent,这是怎么回事。 Thanks in Advance. 提前致谢。

Query : 查询:

  select *
  from rdt_organization 
  connect by prior parentid = 102;

Table Content : 表内容:

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

Output Expected : 预期产量:

id  parentid  
102 null
103 102
112 102
104 103

You need to connect the rows to the PRIOR row using id and parentid, and use START WITH to decide where to start; 您需要使用id和parentid将行连接到PRIOR行,并使用START WITH决定从何处开始。

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

An SQLfiddle to test with . 要使用进行测试的SQLfiddle

Start with is missing 开头缺少

 select *
  from rdt_organization
  start with id = 102  
  connect by prior id = parentid;

Add START WITH id = 102 in the query and try, 在查询中添加START WITH id = 102并尝试,

WITH rdt_organization(ID, parentid) AS
(
SELECT 102, NULL FROM DUAL
UNION ALL
SELECT 103,102 FROM DUAL
UNION ALL
SELECT 112, 102 FROM DUAL
UNION ALL
SELECT 104, 103 FROM DUAL
UNION ALL
SELECT 105, NULL FROM DUAL
UNION ALL
SELECT 106, 105 FROM DUAL
)
SELECT *
FROM   rdt_organization 
START WITH id = 102
CONNECT BY PRIOR ID = parentid;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM