Home » SQL & PL/SQL » SQL & PL/SQL » sql query for employees based on Org hierarchy (R12.1.3, 11g)
sql query for employees based on Org hierarchy [message #630272] Tue, 23 December 2014 23:59 Go to next message
afzaa2yahoocom
Messages: 24
Registered: April 2011
Location: Dubai
Junior Member
Hi All,


I need a query to get employee information based on the Org hierarchy.

I tried using previous queries in this forum and from internet, but didnt get closer.

Below is the requirement:

Level1	Level 2	Level 3
Org Id 81		
	102	
	103	
	104	
		111 (parent 104)
		112(parent 104)
	105	

 

My requirement is to group employees based on the Level 2 which should include the employees from Level 3 in the respective level2 parent id.



Kindly suggest.


    Query to get hierarchy:  
    SELECT  
    LPAD(' ',10*(LEVEL-1)) || org.name hierarchy,ose.organization_id_parent,  
    org.organization_id  
    FROM  
    hr_all_organization_units org,  
    per_org_structure_elements ose  
    WHERE 1=1  
    AND org.organization_id = ose.organization_id_child  
    AND ose.org_structure_version_id = 61  
    --and org.organization_id = 340  
    START WITH  
    ose.organization_id_parent = 81  
    CONNECT BY PRIOR  
    ose.organization_id_child = ose.organization_id_parent  
    ORDER SIBLINGS BY  
    org.location_id,  
    ose.organization_id_child   
      
    Required  Columns:  
      
    SELECT haou.name, papf.EMPLOYEE_NUMBER, papf.full_name  
    FROM   
    per_org_structure_elements ose  
    ,hr_all_organization_units haou  
    ,per_all_assignments_f paaf  
    ,per_all_people_f papf  
    WHERE ose.ORGANIZATION_ID_PARENT = 81  
    AND ose.ORG_STRUCTURE_VERSION_ID = 61  
    AND haou.organization_id = ose.organization_id_child  
    --and paaf.organization_id = ose.organization_id_child  
    and papf.person_id = paaf.person_id  
    and paaf.organization_id = haou.organization_id  
    and :P_GIVEN_DATE between papf.effective_start_date and papf.effective_end_date  
    and :P_GIVEN_DATE between paaf.effective_start_date and paaf.effective_end_date  



Thanks & Regards,

Afzal.
Re: sql query for employees based on Org hierarchy [message #630281 is a reply to message #630272] Wed, 24 December 2014 01:36 Go to previous message
Michel Cadot
Messages: 68643
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Previous Topic: Dynamic PL/SQL which reads table and transposes rows to columns
Next Topic: source does not have runnable target
Goto Forum:
  


Current Time: Tue Apr 23 01:20:46 CDT 2024