SELECT n.*, CONNECT_BY_ROOT(id), level
FROM elements n
START WITH
id IN
(
SELECT MIN(id)
FROM (
SELECT id, CONNECT_BY_ROOT(id) AS root
FROM elements
START WITH
id IN
(
SELECT id
FROM elements n
WHERE CONNECT_BY_ISCYCLE = 1
CONNECT BY NOCYCLE
father_id = PRIOR id
)
CONNECT BY NOCYCLE
id = PRIOR father_id
)
GROUP BY
root
)
CONNECT BY NOCYCLE
id = PRIOR father_id
Misschien wil je dit artikel lezen: