Connecting Tech Pros Worldwide Forums | Help | Site Map

get all hierarchy data

salesmr's Avatar
Newbie
 
Join Date: Jun 2007
Posts: 6
#1: Sep 23 '07
I have created a query using the connect by prior syntax to get a list of all employees and their hierarchy, but am trying to store this information in a table starting with the employee and storing their management information all the way up to our president.

For example,
Employee ID -> Direct Supervisor ID -> Manager ID -> Senior Manager ID -> Director ID -> VP ID -> Pres ID

for each employee. Obviously some will have more levels than other employees, but need to have this dynamic.

Currently, I have this query, but cannot figure out how to get data from hierarchy to table format as discussed above:

SELECT lpad(' ', (level - 1) * 4) || emp_name, level
from hr_employees
where emp_status = 'Active'
CONNECT BY manager_id = prior emp_id
START WITH emp_id = '123456'

Please help....thanks, Michelle

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Sep 24 '07

re: get all hierarchy data


Quote:

Originally Posted by salesmr

I have created a query using the connect by prior syntax to get a list of all employees and their hierarchy, but am trying to store this information in a table starting with the employee and storing their management information all the way up to our president.

For example,
Employee ID -> Direct Supervisor ID -> Manager ID -> Senior Manager ID -> Director ID -> VP ID -> Pres ID

for each employee. Obviously some will have more levels than other employees, but need to have this dynamic.

Currently, I have this query, but cannot figure out how to get data from hierarchy to table format as discussed above:

SELECT lpad(' ', (level - 1) * 4) || emp_name, level
from hr_employees
where emp_status = 'Active'
CONNECT BY manager_id = prior emp_id
START WITH emp_id = '123456'

Please help....thanks, Michelle

If you want to insert the data returned by the above select query you can use the following logic to insert into another table:

Expand|Select|Wrap|Line Numbers
  1.  
  2. INSERT INTO tab1 (SELECT lpad(' ', (level - 1) * 4) || emp_name, level
  3. from hr_employees 
  4. where emp_status = 'Active' 
  5. CONNECT BY manager_id = prior emp_id
  6. START WITH emp_id = '123456')
  7.  
Make sure the table tab1 have 2 columns to insert the data returned by SELECT query
salesmr's Avatar
Newbie
 
Join Date: Jun 2007
Posts: 6
#3: Sep 24 '07

re: get all hierarchy data


Maybe I wasn't clear in what I was asking. Ultimately I want something similar to the "sys_connect_by_path" (so that I can see ALL of the parents to a child), but I have 8 rather than 9i so it is not an option for me to use this function. I'm trying to reproduce the output though. Is this something that you can help with?

Thanks, Michelle
Reply