Академический Документы
Профессиональный Документы
Культура Документы
Function
MOHIT PATEL
6
SELECTemployee_id,manager_id,
LEVEL, sys_connect_by_path(lastname,/) , connect_by_root firstname f
FROMemployee
4
WHERE
employee_id = 4
1
STARTWITHemployee_id=1
2
CONNECTBYNOCYCLE
PRIORemployee_id=manager_id
AND
3 employee_id != 5
5
ORDER
BY LEVEL;
ORDER SIBLINGS BY employee_id
1. It will start with the root Node condition. Multiple roots can be there satisfying the condition
2. Parents employee_id will be connected to childs manager_id. PRIOR is used to identify the
Parent. NOCYCLE is used to avoid any cycle in the hierarchy.
3. Every time after the link between parent and child is made, AND condition is checked. If it fails
then all its subsequent child will not be fetched
4. After all records are selected, records are removed according to the WHERE condition
mentioned
5. ORDER BY clause is mentioned to ORDER the results
** Root is marked as LEVEL 1
emp
id
mngr firstna
id
me
lastna
me
Lastna
me
Em
p
path
Raj
Patel
Raj
Patel
/Patel
Rahul
Bhatt
Rahul
Bhatt
/Patel/Bhatt
Mohit
Patel
Rajesh
Chou
Rajesh
Chou
Suresh
Uber
/
Patel/Bhatt/Cho
u
Deep
Saha
Suresh
Uber
Parth
Saha
/
Patel/Bhatt/Ube
r
Mohit
Patel
/Patel/Patel
Deep
Saha
/
Patel/Patel/Saha
7
3
Parth
select employee_id, manager_id, firstname, last_name
, connect_by_root employee_id emp
3 path1
Mohit
, sys_connect_by_path(last_name,'/')
6
3
Deep
FROM emp
START WITH last_name='Patel'
7
3
Parth
CONNECT BY NOCYCLE prior employee_id=manager_id
Saha
/
Patel/Patel/Saha
Patel
/Patel
Saha
/Patel/Saha
Saha
/Patel/Saha