Emp_Details_Report
Table1: per_all_people_f
select 
person_id,
person_number,
to_char(trunc(start_date),'yyyy-mm-dd')
from
per_all_people_f --(person_number,start_date)
where
person_number=:P_person_number --Bind Parameter.
--and nvl(:P_person_number,P_person_number)--Optional Parameter
AND sysdate between EFFECTIVE_START_DATE and EFFECTIVE_END_DATE

----------------------
Table2:
Per_person_names_f --person_name
select
FULL_NAME 
from
Per_person_names_f
where
--PERSON_ID=300000047606113
and NAME_TYPE='GLOBAL'
--------------------------------------------------
Table3:per_people_legislative_f
select
sex as gender,
marital_status
from
per_people_legislative_f
where
person_id=<enter_id>
---------------------------------------
Table4:per_persons
select
date_of_birth
from
per_persons
where
person_id=<enter_id>

Now, we will join the tables to get the Report
=================================
Bind Parameter is mandatory:
----------------------------
select 
papf.person_id,
papf.person_number,
papf.start_date,
ppnf.full_name emp_name,
pplf.sex gender,
pplf.marital_status,
pp.date_of_birth
from
per_all_people_f papf,
per_person_names_f ppnf,
per_people_legislative_f pplf,
per_persons pp 
where
papf.person_number=:P_person_number
--1st and 2nd table join condition
AND papf.PERSON_ID=ppnf.PERSON_ID
AND sysdate between papf.EFFECTIVE_START_DATE and papf.EFFECTIVE_END_DATE
AND sysdate between ppnf.EFFECTIVE_START_DATE and ppnf.EFFECTIVE_END_DATE
AND ppnf.name_type='GLOBAL'
--2nd and 3rd table join condition
AND ppnf.person_id=pplf.person_id 
AND sysdate between pplf.EFFECTIVE_START_DATE and pplf.EFFECTIVE_END_DATE
--1st and 4th table join condition(1st table is the central table)
and papf.person_id=pp.person_id

Optional Parameter
-----------------------
select 
papf.person_id,
papf.person_number,
papf.start_date,
ppnf.full_name emp_name,
pplf.sex gender,
pplf.marital_status,
pp.date_of_birth
from
per_all_people_f papf,
per_person_names_f ppnf,
per_people_legislative_f pplf,
per_persons pp 
where
papf.person_number=nvl(:P_person_number,papf.person_number)
--1st and 2nd table join condition
AND papf.PERSON_ID=ppnf.PERSON_ID
AND sysdate between papf.EFFECTIVE_START_DATE and papf.EFFECTIVE_END_DATE
AND sysdate between ppnf.EFFECTIVE_START_DATE and ppnf.EFFECTIVE_END_DATE
AND ppnf.name_type='GLOBAL'
--2nd and 3rd table join condition
AND ppnf.person_id=pplf.person_id 
AND sysdate between pplf.EFFECTIVE_START_DATE and pplf.EFFECTIVE_END_DATE
--1st and 4th table join condition(1st table is the central table)
and papf.person_id=pp.person_id

Comments

Popular posts from this blog

Oracle SQL

SubQueries

With Clause