top of page

CONNECT BY PRIOR / Hierarchical Queries / Query Tree Structure

Writer's picture: Rumesh Aponso (RMAX)Rumesh Aponso (RMAX)

Example 1:

SELECT  handling_unit_id, t.shipment_id
FROM    handling_unit_tab t
START   WITH handling_unit_id = '4558'
CONNECT BY PRIOR handling_unit_id = parent_handling_unit_id;

Example 2:

SELECT LEVEL, parent_node_id, node_id
FROM   (SELECT parent_node_id, node_id
        FROM   estimate_node_tab
        WHERE  estimate_id          = 77
        AND    estimate_revision_no = 1)
START   WITH parent_node_id      = 0
CONNECT BY NOCYCLE PRIOR node_id = parent_node_id
ORDER   BY parent_node_id;

Example 3:

SELECT  level, SYS_CONNECT_BY_PATH(ename, '/') path
FROM    emp
START   WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr;

Output:
LEVEL PATH
----- ---------------------------------------------------------------
1     /KING
2     /KING/JONES
3     /KING/JONES/SCOTT

Related Links:



3 views0 comments

Related Posts

See All

LISTAGG in PLSQL

Example 1: SELECT DISTINCT LISTAGG(t.commission_receiver, ';') WITHIN GROUP (ORDER BY t.commission_receiver) FROM...

Get Foundation Error from ORA Error

FUNCTION Strip_Ora_Error ( sqlerrm_        IN VARCHAR2,    sqlcode_        IN NUMBER DEFAULT NULL,    strip_ora_only_ IN BOOLEAN DEFAULT...

Comments


Copyright © 2025 RMAXOneNote

  • Online CV
  • LinkedIn
  • Youtube
  • GitHub
  • Blogger
bottom of page