Em um ambiente de banco de dados, as chaves estrangeiras no nível superior provavelmente serão nulas, assim:
| pid | cid |
|------*------|
| null | 2 |
| 2 | 3 |
| 3 | 4 |
| null | 6 |
| 6 | 7 |
| 7 | 8 |
Então eu recomendo usar algo como:
select connect_by_root(t1.cid) as startpoint,
t1.cid as rootnode
from your_table t1
where connect_by_isleaf = 1
start with t1.cid in (8, 4)
connect by prior t1.pid = t1.cid;
violino