Oracle - Recursive query using START WITH… CONNECTED BY…?

余生长醉 提交于 2019-12-24 13:25:59

问题


Say i have the following table, using Oracle 10g

 ARTIFACT_LABEL |   DEPENDANT_ON
 test1          |   abc1
 test1          |   abc2
 test1          |   abc3
 abc3           |   xyz1
 abc4           |   xyz2

and i want to generate a tree structure knowing what test1 depends on, (so i want to return, abc1, abc2, abc3, xyz1) ive been using the following:

SELECT ARTIFACT_LABEL, DEPENDANT_ON FROM DEPENDANCIES START WITH ARTIFACT_LABEL = 'test1' CONNECT BY NOCYCLE PRIOR ARTIFACT_LABEL = DEPENDANT_ON

But this isnt working (it seems to just be doing a SELECT where ARTIFACT_LABEL = 'test1')

Any ideas where im going wrong?


回答1:


Since you are starting at the bottom of the tree and working up, change the last part of the query to:

PRIOR DEPENDANT_ON = ARTIFACT_LABEL


来源:https://stackoverflow.com/questions/7149962/oracle-recursive-query-using-start-with-connected-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!