0% found this document useful (0 votes)
143 views8 pages

Oracle ETL Queries

The document contains SQL queries to retrieve employee data from an HR database including organization hierarchy, active employees, monthly new hires, employee details with supervisor info, salary increase history, employee transfers/rehires, terminated employees, employee leave history, and SIT/EIT identification information.

Uploaded by

Manoj Chawla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views8 pages

Oracle ETL Queries

The document contains SQL queries to retrieve employee data from an HR database including organization hierarchy, active employees, monthly new hires, employee details with supervisor info, salary increase history, employee transfers/rehires, terminated employees, employee leave history, and SIT/EIT identification information.

Uploaded by

Manoj Chawla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

--=============================================

-- Organisation Hierarchy
--=============================================
SELECT name
,type
,organization_id
FROM (SELECT hou.name
,type
,organization_id
FROM hr_all_organization_units hou
WHERE organization_id IN
(SELECT organization_id_child organization_id
FROM (SELECT organization_id_child
,organization_id_parent
,org_structure_version_id
FROM per_org_structure_elements
WHERE org_structure_version_id
IN
(SELECT posv.org_structure_version_id
FROM per_organization_structures pos
,per_org_structure_versions posv
WHERE primary_structure_flag
= 'Y'
AND pos.organization_structure_id
= posv.organization_structure_id
AND pos.name
= 'NATO Hierarchy')
)
CONNECT by organization_id_child
= prior organization_id_parent
START WITH organization_id_child = 81)
AND UPPER(hou.type) = UPPER('Business Group'))
WHERE ROWNUM = 1;

--=============================================
-- Find total active employee IN the company
--=============================================
SELECT ppf.employee_number
,ppf.full_name
,ppf.email_address
FROM per_all_people_f ppf
WHERE ppf.current_employee_flag = 'Y'
AND TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND ppf.employee_number IS NOT NULL
AND ppf.person_type_id = (SELECT person_type_id
FROM per_person_types
WHERE user_person_type = 'Employee'
AND business_group_id =
ppf.business_group_id)

--=============================================
-- Get month wise hired employees head count
--=============================================
SELECT TO_CHAR(original_date_of_hire,'MON') mm
,count(person_id) total
FROM per_people_x
WHERE TO_CHAR(original_date_of_hire,'RRRR') = '2014'
GROUP BY TO_CHAR(original_date_of_hire,'MON')
--
===================================================================================
=====
-- provide a list of active employees along WITH their supervisor's name AND email
address
--
===================================================================================
=====
SELECT ppf.employee_number
,ppf.full_name
,ppf.email_address
,paaf.supervisor_id
,sup.full_name
,sup.email_address
FROM per_all_people_f ppf
,per_all_assignments_f paaf
,per_people_x sup
WHERE ppf.current_employee_flag = 'Y'
AND paaf.supervisor_id (+) = sup.person_id
AND TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND TRUNC(sysdate) BETWEEN paaf.effective_start_date
AND paaf.effective_end_date
AND ppf.person_id = paaf.person_id
AND ppf.employee_number IS NOT NULL
AND ppf.employee_number = '539988'
AND ppf.person_type_id = (SELECT person_type_id
FROM per_person_types
WHERE user_person_type = 'Employee'
AND business_group_id =
ppf.business_group_id)

--
===================================================================================
=====
-- get the employee salary increase summary
--
===================================================================================
=====

SELECT ppf.employee_number
,ppf.full_name
,ppp.proposed_salary_n
,ppp.change_date
FROM per_pay_proposals ppp
,per_all_people_f ppf
,per_all_assignments_f paaf
WHERE ppf.person_id = paaf.person_id
AND paaf.assignment_id = ppp.assignment_id
AND ppf.employee_number = '603167'
AND TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND TRUNC(sysdate) BETWEEN paaf.effective_start_date
AND paaf.effective_end_date
AND ppp.approved = 'Y'
AND change_date = (SELECT MIN(change_date)
FROM per_pay_proposals
WHERE assignment_id =
ppp.assignment_id
AND proposed_salary_n =
ppp.proposed_salary_n)
order BY ppp.change_date desc;

--
===================================================================================
=====
-- Get the history for an employee's transfers IN the company
-- Get the list of employee who were terminated AND have been rehired
--
===================================================================================
=====
SELECT ppf.employee_number
,ppf.full_name
,ppf.email_address
FROM per_all_people_f ppf
WHERE TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND person_id IN (SELECT person_id
FROM (SELECT count(1)
,person_id
FROM per_periods_of_service
GROUP BY person_id
having count(1) > 1))

--
===================================================================================
=====
-- Get the list of terminated employees
--
===================================================================================
=====
SELECT ppf.employee_number
,ppf.full_name
,ppf.email_address
FROM per_all_people_f ppf
WHERE TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND current_employee_flag IS NULL
AND ppf.person_type_id = (SELECT person_type_id
FROM per_person_types
WHERE UPPER(user_person_type) = UPPER('Ex-
Employee')
AND business_group_id =
ppf.business_group_id)

--
===================================================================================
=====
-- Get an employees leave history
--
===================================================================================
=====
SELECT a.date_start
,a.date_end
,a.absence_days
,(SELECT name
FROM per_absence_attendance_types
WHERE absence_attendance_type_id = a.absence_attendance_type_id
AND business_group_id =a.business_group_id)
leave_type
FROM per_absence_attendances a
WHERE person_id = (SELECT person_id
FROM per_all_people_f
WHERE employee_number
= '47457'
AND employee_number IS
NOT NULL)
ORDER BY date_start desc;

--
===================================================================================
=====
-- Get EIT based information for employees
-- For e.g. P&I Card
--
===================================================================================
=====
SELECT ppf.employee_number
,ppf.full_name
,ppei.*
FROM per_all_people_f ppf
,per_people_extra_info ppei
WHERE ppf.person_id = ppei.person_id
AND TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND ppf.employee_number = '603167'
AND ppei.information_type = 'EIT NAME XXXXXXXX' -- EIT name

--
===================================================================================
=====
-- Get SIT based information for employees
--
===================================================================================
=====
SELECT ppf.employee_number
,ppf.full_name
,pac.segment10 type
,segment1 id_number
,segment20 issuedt
,segment30 expdt
,segment11 issueplace
,segment17 issuingcountry
,segment12 issuing_authority
,segment18 primaryflag
FROM per_person_analyses ppa
,per_analysis_criteria pac
,fnd_id_flexs fif
,fnd_id_flex_structures fis
,fnd_id_flex_structures_tl stl
,per_all_people_f ppf
WHERE ppa.analysis_criteria_id = pac.analysis_criteria_id
AND fif.id_flex_code = fis.id_flex_code
AND ppa.person_id = ppf.person_id
AND pac.id_flex_num = fis.id_flex_num
AND stl.id_flex_num = fis.id_flex_num
-- Parameters
AND TRUNC(sysdate) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND ppf.employee_number = '602201'
AND stl.id_flex_structure_name
= 'SIT NAME XXXXXXXXXX'

--
===================================================================================
=====
-- Get the list of all organization which are below an organization in org
hierarchy
--
===================================================================================
=====
SELECT hp.name parent_org
,hc.name child_organization
FROM per_org_structure_elements pose
,per_org_structure_versions posv
,hr_all_organization_units hc
,hr_all_organization_units hp
WHERE 1=1
AND pose.business_group_id = posv.business_group_id
AND pose.organization_id_child = hc.organization_id
AND pose.organization_id_parent = hp.organization_id

--
===================================================================================
=====
-- provide the list of employees current AND previous assignment details
-- (shows employee organization change history. like wise we can change the query
to
-- show the history of grade, payroll, organization, location, position, job
-- change summary)
--
===================================================================================
=====
SELECT ppf.employee_number
,paaf.assignment_number
,ppf.full_name
,paaf.organization_id current_org_id
,paaf.effective_start_date curr_org_start_date
,(SELECT name
FROM hr_all_organization_units
WHERE organization_id = paaf.organization_id)
current_org_name
,paaf_prev.effective_start_date
prev_org_start_date
,paaf_prev.organization_id prev_org_id
,(SELECT name
FROM hr_all_organization_units
WHERE organization_id = paaf_prev.organization_id)
prev_org
FROM per_all_assignments_f paaf
,per_all_assignments_f paaf_prev
,pay_people_groups ppg
,pay_people_groups ppg_prev
,per_all_people_f ppf
WHERE paaf_prev.effective_end_date + 1
= paaf.effective_start_date
AND paaf_prev.assignment_id = paaf.assignment_id
AND paaf_prev.assignment_type = 'E'
AND ppf.employee_number = '557331'
AND paaf.assignment_type = 'E'
AND paaf.organization_id <> paaf_prev.organization_id
AND paaf.people_group_id = ppg.people_group_id
AND paaf_prev.people_group_id = ppg_prev.people_group_id
AND paaf.effective_start_date
BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND paaf.person_id = ppf.person_id
ORDER BY paaf_prev.effective_start_date desc

--
===================================================================================
=====
-- Employee short leave details AND hours calculation
--
===================================================================================
=====
SELECT paa.person_id
,paa.date_start
,paa.date_end
,time_start
,time_end
,round ( ( ((substr(time_end,1,2) -substr(time_start,1,2)) * 60
+ (substr(time_end,4,2) -substr(time_start,4,2))) / 60 ) ,2) hours
FROM per_absence_attendances paa
,per_absence_attendance_types paat
WHERE paa.person_id = 68567
AND paa.absence_attendance_type_id
= paat.absence_attendance_type_id
AND paat.name = 'Annual Leave' -- Absence Type
AND paa.date_START BETWEEN :p_period_start_date
AND :p_period_end_date
AND paa.date_end BETWEEN :p_period_start_date
AND :p_period_end_date

--
===================================================================================
=====
-- OLM - Find the tests, applicants AND their number of attempt for each test
--
===================================================================================
=====
SELECT tests.parent_category
,tests.category
,tests.catalog_course_obj_code
,tests.catalog_course_obj
,folder
,tests.test_name
,tests.offering_name
,tests.test_instance_name
,mv.employee_number
,mv.full_name
,odb.date_booking_placed enrolled_date
,obst.name test_status
,(SELECT count(1)
FROM ota_attempts
WHERE event_id = oe.event_id
AND user_id = odb.delegate_person_id
AND attempt_status IN ('F','P','C')
AND raw_status IN ('I', 'C')
AND suspend_data IS NULL)
no_of_attempts
,mv.person_id
,oe.event_id
FROM ota_delegate_bookings odb
,ota_events oe
,ota_booking_status_types obst
,xxalb_catl_obj_tests_v tests
,per_all_people_f mv
WHERE 1=1
AND odb.event_id=oe.event_id
AND obst.booking_status_type_id = odb.booking_status_type_id
AND obst.business_group_id = odb.business_group_id
AND oe.event_id = tests.event_id
AND delegate_person_id = mv.person_id
AND TRUNC(sysdate) BETWEEN mv.effective_start_date AND effective_end_date
–-AND mv.employee_number = '603167'
ORDER BY oe.event_id
,odb.date_booking_placed

--=============================================
-- Payroll - Query to get the element history for an employee
--=============================================
SELECT ppf.person_id
,period_name
,pet.element_name
,prrv.result_value
,ppos.person_id
FROM per_people_f ppf
,apps.pay_element_types_f pet
,apps.pay_input_values_f piv
,apps.pay_run_result_values prrv
,apps.pay_run_results prr
,apps.pay_payroll_actions ppa
,apps.pay_assignment_actions paa
,apps.pay_element_classifications
pec
,apps.per_time_periods ptp
,apps.per_assignments_f paf
,apps.pay_payrolls_f pay
,apps.per_periods_of_service ppos
WHERE ppf.person_id = paf.person_id
AND paf.assignment_id = paa.assignment_id
AND piv.name = 'pay value'
AND prrv.input_value_id = piv.input_value_id
AND piv.element_type_id = pet.element_type_id(+)
AND prr.run_result_id = prrv.run_result_id
AND paa.payroll_action_id = ppa.payroll_action_id
AND prr.assignment_action_id = paa.assignment_action_id
AND pet.element_type_id = prr.element_type_id
AND ppa.action_type IN ('Q', 'R')
AND pet.classification_id = pec.classification_id
AND ptp.time_period_id = ppa.time_period_id(+)
AND pay.payroll_id = paf.payroll_id
AND ppos.person_id = ppf.person_id
AND ptp.payroll_id = paf.payroll_id
AND NVL(ppa.date_earned, ppa.effective_date)
BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND NVL(ppa.date_earned, ppa.effective_date)
BETWEEN piv.effective_start_date
AND piv.effective_end_date
AND NVL(ppa.date_earned, ppa.effective_date)
BETWEEN paf.effective_start_date
AND paf.effective_end_date
AND NVL(ppa.date_earned, ppa.effective_date)
BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
--parameters
AND ppf.employee_number = '600099'
--AND UPPER(pet.element_name) LIKE '%commission%'
AND ptp.start_date BETWEEN '01-Jan-2014′
AND '28-Nov-2015′
AND ptp.start_date BETWEEN
last_day(add_months(ppos.actual_termination_date,-7))+1
AND
last_day(add_months(ppos.actual_termination_date,-1))

--
===================================================================================
=====
-- Get the oracle balance values
--
===================================================================================
=====
SELECT pdb.defined_balance_id
,dim.dimension_name
FROM pay_defined_balances pdb
,pay_balance_types typ
,pay_balance_dimensions dim
WHERE pdb.balance_type_id = typ.balance_type_id
AND pdb.balance_dimension_id = dim.balance_dimension_id
AND dim.legislation_code = (SELECT legislation_code
FROM per_business_groups
WHERE business_group_id =
83) ---PLEASE CHECK
AND UPPER(typ.balance_name) = UPPER('indemnity days') --- BALANCE NAME
AND UPPER(dim.dimension_name) = UPPER ('assignment run');

SELECT pay_balance_pkg.get_value(p_balance_id
,p_assignment_action_id
,TRUNC(sysdate))
FROM dual
-- TRUNC(sysdate) will return you balance value as of date, you can use any old
date as per your requirement.

You might also like