0

Does anybody know of a way to know the depth of the CONNECT BY? For example if I had;

PARENT_ID   PARENT_KEY  CHILD_ID    CHILD_KEY
1           BOB         2           CHRIS
1           BOB         3           TODD
2           CHRIS       4           JON
2           CHRIS       5           ALF
5           ALF         6           GERARD
5           ALF         7           MIKE
3           TODD        8           ANN
3           TODD        9           FRED

The depth of CHRIS is 3 and the depth of TODD is 2, How would I find out the depth of CHRIS and TODD programatically where;

START WITH PARENT_KEY = 'BOB' CONNECT BY PRIOR CHILD_ID = PARENT_ID

Sorry, I was being stupid...here is the answer for those who have brain lapses in the future;

SELECT
PARENT_KEY
, MAX(LEVEL) AS DEPTH
FROM TIMELINE_CONFIG
START WITH PARENT_KEY = 'BOB' CONNECT BY PRIOR CHILD_ID = PARENT_ID
GROUP BY PARENT_KEY
cbm64
  • 1,059
  • 2
  • 12
  • 24

2 Answers2

4

You can use the LEVEL pseudo-column:

SELECT ..., LEVEL, ...
FROM ...
Corrado Piola
  • 859
  • 1
  • 14
  • 18
0

Sorry, I was being stupid...here is the answer for those who have brain lapses in the future;

SELECT
PARENT_KEY
, MAX(LEVEL) AS DEPTH
FROM TIMELINE_CONFIG
START WITH PARENT_KEY = 'BOB' CONNECT BY PRIOR CHILD_ID = PARENT_ID
GROUP BY PARENT_KEY
cbm64
  • 1,059
  • 2
  • 12
  • 24