先前连接

时间:2013-12-11 13:18:10

标签: sql oracle

如何突破第三次嵌套的查询?

 SELECT CHILD_ID
   FROM COLLECTION_ITEMS 
  START WITH PARENT_ID = 16917 
CONNECT BY PRIOR CHILD_ID = PARENT_ID

我有这样的查询,如果嵌套增加到三个以上我必须结束查询。

1 个答案:

答案 0 :(得分:3)

您可以使用LEVEL伪列。

SELECT
  CHILD_ID
FROM
  COLLECTION_ITEMS
WHERE
  LEVEL <= 3
  START WITH PARENT_ID      = 16917
  CONNECT BY PRIOR CHILD_ID = PARENT_ID