Hierarchy Operator

Purpose: Used to query hierarchical data using a parent-child relationship.Syntax:

SELECT column1, column2, LEVEL FROM table_name START WITH condition CONNECT BY PRIOR parent_column = child_column;

Example:

SELECT employee_id, first_name, manager_id, LEVEL
FROM employees
START WITH manager_id IS NULL
CONNECT BY PRIOR employee_id = manager_id;

Explanation: This retrieves a hierarchy of employees starting from those without a manager (top level).


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *