Today i come across new oracle Function "onnect by Prior "
CONNECT BY PRIOR
Desc:-
A condition that identifies the relationship between parent rows and child rows of the hierarchy
Syntax:-
CONNECT BY
Example :-
SELECT employee_id, last_name, manager_id
FROM employees
CONNECT BY PRIOR employee_id = manager_id;
To show Level
First to note here is a pseudo column named "level" (similar to rownum) available with connect by clause showing
where in the hierarchy is current row. We could use it to show the hierarchy in list more visible.
SQL> SELECT LEVEL, lpad(' ', LEVEL*2) || ename ename
2 FROM emp
3 START WITH mgr IS NULL
4 CONNECT BY PRIOR empno = mgr;
No comments:
Post a Comment