[Solved] How to use recursively to query get node after root one level (details see in the photo attach)?


Oracle Setup:

CREATE your_table ( source, target ) AS
  SELECT '0',     '1' FROM DUAL UNION ALL
  SELECT '0',     '2' FROM DUAL UNION ALL
  SELECT '0',     '3' FROM DUAL UNION ALL
  SELECT '1',     '1.1' FROM DUAL UNION ALL
  SELECT '1',     '1.2' FROM DUAL UNION ALL
  SELECT '1',     '1.3' FROM DUAL UNION ALL
  SELECT '2',     '2.1' FROM DUAL UNION ALL
  SELECT '2',     '2.2' FROM DUAL UNION ALL
  SELECT '3',     '3.1' FROM DUAL UNION ALL
  SELECT '1.1',   '1.1.1' FROM DUAL UNION ALL
  SELECT '1.1',   '1.1.2' FROM DUAL UNION ALL
  SELECT '1.1',   '1.1.3' FROM DUAL UNION ALL
  SELECT '1.1.2', '1.1.2.1' FROM DUAL UNION ALL
  SELECT '1.1.2', '1.1.2.2' FROM DUAL UNION ALL
  SELECT '1.1.2', '1.1.2.3' FROM DUAL;

Query:

SELECT CONNECT_BY_ROOT( target ) AS first_child
FROM   your_table
WHERE  target="1.1.2.2"
START WITH source="0"
CONNECT BY PRIOR target = source;

Output:

FIRST_CHILD
-----------
1

solved How to use recursively to query get node after root one level (details see in the photo attach)?