function get_record_history(p_create_id in varchar2,
p_update_id in varchar2,
p_create_date in varchar2,
p_update_date in varchar2
) return varchar2
is
l_result_line varchar2(32000);
l_create_person varchar2(150);
l_create_org_id varchar2(150);
l_create_job varchar2(150);
l_create_contact varchar2(150);
l_update_person varchar2(150);
l_update_org_id varchar2(150);
l_update_job varchar2(150);
l_update_contact varchar2(150);
l_is_person varchar2(1);
l_create_organization_id number;
l_update_organization_id number;
l_create_id varchar2(150) := p_create_id;
l_update_id varchar2(150) := p_update_id;
l_create_date varchar2(150) := p_create_date;
l_update_date varchar2(150) := p_update_date;
begin
if l_create_id is null then
return '';
end if;
select case when user_det.full_name is null then
fnu.user_name
else
decode(regexp_substr(upper(user_det.full_name),'I'), null, user_det.full_name, fnu.user_name) || ' ' ||
user_det.employee_number end,
decode(user_det.full_name, null, 'N', 'Y') into l_create_person, l_is_person
from FND_USER fnu,
per_all_people_f user_det
where fnu.employee_id = user_det.person_id(+)
and trunc(sysdate) between user_det.effective_start_date(+) and user_det.effective_end_date(+)
and fnu.user_id = to_number(l_create_id);
--
if l_is_person = 'Y' then
begin
select asg.organization_id into l_create_organization_id
from per_all_people_f user_det,
per_all_assignments_f asg,
FND_USER fnu
where user_det.person_id = asg.person_id
and fnu.employee_id = user_det.person_id
and trunc(sysdate) between user_det.effective_start_date and user_det.effective_end_date
and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
and fnu.user_id = to_number(l_create_id);
exception
when NO_DATA_FOUND then
null;
end;
--
begin
select j.name into l_create_job
from per_all_people_f user_det,
per_all_assignments_f asg,
FND_USER fnu,
per_jobs j
where user_det.person_id = asg.person_id
and fnu.employee_id = user_det.person_id
and asg.job_id = j.job_id
and trunc(sysdate) between user_det.effective_start_date and user_det.effective_end_date
and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
and trunc(sysdate) >= j.date_from and j.date_to is null
and fnu.user_id = to_number(l_create_id)
and rownum = 1;
exception
when NO_DATA_FOUND then
null;
end;
--
begin
select coalesce(user_det.email_address, fnu.Email_Address, ' ') || ' ' ||
user_det.work_telephone
into l_create_contact
from per_all_people_f user_det,
per_all_assignments_f asg,
FND_USER fnu
where user_det.person_id = asg.person_id
and fnu.employee_id = user_det.person_id
and trunc(sysdate) between user_det.effective_start_date and user_det.effective_end_date
and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
and fnu.user_id = to_number(l_create_id);
exception
when NO_DATA_FOUND then
null;
end;
end if;
--------------------------
l_is_person := '';
--------------------------
select case when user_det.full_name is null then
fnu.user_name
else
decode(regexp_substr(upper(user_det.full_name),'I'), null, user_det.full_name, fnu.user_name) || ' ' ||
user_det.employee_number end,
decode(user_det.full_name, null, 'N', 'Y') into l_update_person, l_is_person
from FND_USER fnu,
per_all_people_f user_det
where fnu.employee_id = user_det.person_id(+)
and trunc(sysdate) between user_det.effective_start_date(+) and user_det.effective_end_date(+)
and fnu.user_id = to_number(l_update_id);
if l_is_person = 'Y' then
begin
select asg.organization_id into l_update_organization_id
from per_all_people_f user_det,
per_all_assignments_f asg,
FND_USER fnu
where user_det.person_id = asg.person_id
and fnu.employee_id = user_det.person_id
and trunc(sysdate) between user_det.effective_start_date and user_det.effective_end_date
and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
and fnu.user_id = to_number(l_update_id);
exception
when NO_DATA_FOUND then
null;
end;
--
begin
select j.name into l_update_job
from per_all_people_f user_det,
per_all_assignments_f asg,
FND_USER fnu,
per_jobs j
where user_det.person_id = asg.person_id
and fnu.employee_id = user_det.person_id
and asg.job_id = j.job_id
and trunc(sysdate) between user_det.effective_start_date and user_det.effective_end_date
and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
and trunc(sysdate) >= j.date_from and j.date_to is null
and fnu.user_id = to_number(l_update_id);
exception
when NO_DATA_FOUND then
null;
end;
--
begin
select coalesce(user_det.email_address, fnu.Email_Address, ' ') || ' ' ||
user_det.work_telephone
into l_update_contact
from per_all_people_f user_det,
per_all_assignments_f asg,
FND_USER fnu
where user_det.person_id = asg.person_id
and fnu.employee_id = user_det.person_id
and trunc(sysdate) between user_det.effective_start_date and user_det.effective_end_date
and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
and fnu.user_id = to_number(l_update_id);
exception
when NO_DATA_FOUND then
null;
end;
end if;
---------------
select decode(l_create_person, null, '', 'Создал запись ' || l_create_person || chr(10)) into l_create_person from dual;
select decode(l_create_org_id, null, '', 'Структурное подразделение ' || l_create_org_id || chr(10)) into l_create_org_id from dual;
select decode(l_create_job, null, '', 'Должность ' || l_create_job || chr(10)) into l_create_job from dual;
if length(trim(l_create_contact)) > 0 then
l_create_contact := 'Контакты ' || l_create_contact || chr(10);
else
l_create_contact := '';
end if;
select decode(l_create_date, null, '', 'Дата создания записи ' || l_create_date || chr(10)) into l_create_date from dual;
select decode(l_update_person, null, '', 'Изменил запись ' || l_update_person || chr(10)) into l_update_person from dual;
select decode(l_update_org_id, null, '', 'Структурное подразделение ' || l_update_org_id || chr(10)) into l_update_org_id from dual;
select decode(l_update_job, null, '', 'Должность ' || l_update_job || chr(10)) into l_update_job from dual;
if length(trim(l_update_contact)) > 0 then
l_update_contact := 'Контакты ' || l_update_contact || chr(10);
else
l_update_contact := '';
end if;
select decode(l_update_date, null, '', 'Дата изменения записи ' || l_update_date) into l_update_date from dual;
l_result_line := l_create_person ||
l_create_org_id ||
l_create_job ||
l_create_contact ||
l_create_date || chr(10) ||
l_update_person ||
l_update_org_id ||
l_update_job ||
l_update_contact ||
l_update_date;
return l_result_line;
exception
when OTHERS then
return 'Ошибка! p_create_id=' || l_create_id || ';' ||
'l_update_id=' || l_update_id || ';' ||
'l_create_date=' || l_create_date || ';' ||
'l_update_date=' || l_update_date ||
'error info: ' || sqlerrm;
end get_record_history;