SELECT a.business_group_id,
a."person_id",
a.assignment_id,
a."employee_number",
a."full_name",
a."supervisor_id",
a."supervisor_emp_no",
a."supervisor",
a."organization_id",
a."position",
LEVEL level1,
connect_by_root supervisor_emp_no top_supervisor,
connect_by_iscycle loopback,
connect_by_root supervisor_id AS top_supervisor_id,
Sys_connect_by_path (supervisor_emp_no, '/') PATH
FROM (SELECT papf.business_group_id,
papf.person_id,
paaf.assignment_id,
papf.employee_number,
papf.full_name,
paaf.supervisor_id,
papf1.employee_number supervisor_emp_no,
papf1.full_name supervisor,
paaf.organization_id,
hr_general.Decode_position(paaf.position_id) position
FROM per_all_people_f papf,
per_all_assignments_f paaf,
per_all_people_f papf1
WHERE papf.person_id = paaf.person_id
AND papf1.person_id = paaf.supervisor_id
AND papf.current_employee_flag = 'Y'
AND paaf.primary_flag = 'Y'
AND papf.business_group_id = paaf.business_group_id
AND papf1.business_group_id = papf.business_group_id
AND Trunc(SYSDATE) BETWEEN papf.effective_start_date AND
papf.effective_end_date
AND Trunc(SYSDATE) BETWEEN paaf.effective_start_date AND
paaf.effective_end_date
AND Trunc(SYSDATE) BETWEEN papf1.effective_start_date AND
papf1.effective_end_date) a
WHERE connect_by_iscycle > 0
CONNECT BY NOCYCLE PRIOR a.person_id = a.supervisor_id
ORDER SIBLINGS BY a.person_id;
Comments
Post a Comment