Oracle - Recursive query using START WITH… CONNECT

2019-08-15 17:24发布

问题:

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