The below example uses the SCOTT schema’s EMP table to explain how to find out an employee’s level

in the organization hierarchy.

Shown above is the result of the query for SELECT * from EMP. Note EMPNO’s 7698, 7782 AND 7566 are all MANAGER’s and directly report to EMPNO = 7839 (PRESIDENT) i.e. Managers are at Level 2 in the hierarchy and people reporting to their respective managers will be at Level 3 in the hierarchy and so on. Now, in order to determine hierarchy level for Employees, we start from EMPNO = 7839 who is the PRESIDENT and having no MGR to trace the hierarchy from the top (i.e. PRESIDENT) to the bottom. Use the query shown below.

Nelrick Rodrigues

As shown above, EMPNO = 7839 is at level 1, and all the employees who report to him i.e. all the MANAGER’s are at level 2, and employees who report to the MANAGER’s are at level 3 and so on.

Nelrick Rodrigues

Sign up to vote on this title
UsefulNot useful