I don't know exactly how should i implement this in oracle, it just seemed like recursion to me. I have this table
| EMPLOYEES |
-------------------
| employee_id |
-------------------
| manager_id |
___________________
And i want to get the number of all direct and indirect subordinates of a specific employee (given his id as a parameter). To be more specific, every employee (except 1) has a manager, but, x may be the manager of employee b, and employee b could be the manager of employee c, so c is also a subordinate of x. Until now all i could come up with is a list of employee_id and bulk collect first "wave" of subordinates
CREATE OR REPLACE TYPE subordinates AS VARRAY(10) OF NUMBER(4);
/
DECLARE list subordinates;
CREATE OR REPLACE FUNCTION f_sub(v_id employees.employee_id%type) RETURN NUMBER IS
e_count number;
BEGIN
SELECT employee_id BULK COLLECT INTO list
FROM EMPLOYEES
WHERE manager_id = v_id;
return list.count;
end;
connect by