Oracle-使用START WITH ... CONNECTED BY ...的递归查询吗? [英] Oracle - Recursive query using START WITH... CONNECTED BY...?
问题描述
说我有下表,使用的是Oracle 10g
Say i have the following table, using Oracle 10g
ARTIFACT_LABEL | DEPENDANT_ON
test1 | abc1
test1 | abc2
test1 | abc3
abc3 | xyz1
abc4 | xyz2
我想生成一个树结构,知道test1
依赖什么,(所以我想返回,abc1, abc2, abc3, xyz1
)我一直在使用以下内容:
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
SELECT ARTIFACT_LABEL, DEPENDANT_ON
FROM DEPENDANCIES
START WITH ARTIFACT_LABEL = 'test1'
CONNECT BY NOCYCLE PRIOR ARTIFACT_LABEL = DEPENDANT_ON
但这是行不通的(似乎只是在执行SELECT where ARTIFACT_LABEL = 'test1'
)
But this isnt working (it seems to just be doing a SELECT where ARTIFACT_LABEL = 'test1'
)
有什么想法我会出错吗?
Any ideas where im going wrong?
推荐答案
由于您是从树的底部开始并开始工作,因此将查询的最后一部分更改为:
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
这篇关于Oracle-使用START WITH ... CONNECTED BY ...的递归查询吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!