Level
For each row returned through a hierarchical query and the LEVEL pseudocolumn returns 1 for the root node, 2 for a child node and many more. A root node is the highest node within an inverted tree. The child node is any non-root node. The parent node is any row which has children. Leaf node is any row without children. The subsequent diagram describes the nodes of an inverted tree with their LEVEL values.
To describe the hierarchical relationship in a query by use START WITH clause and CONNECT BY clause. The following example describes this:
SELECT LPAD(ENAME,10*LEVEL) FROM EMP
START WITH MGR IS NULL
CONNECT BY MGR=PRIOR EMPNO;
The output of the above query will be:
LPAD(ENAME,10*LEVEL)
Because King is the top most employees so the execution will begin with the start with clause and the next connection will be based on CONNECT BY clause.
In this instance example CONNECT BY MGR=PRIOR EMPNO compares the last selected empno (first King’s employee no) with the matching manager No’s in Manager Column and displays those records under KING and so on.