--以下脚本于20180115在Tony环境成功实现
--更新员工信息
--调用脚本_start
/*begin
APPS.XXUPDATE_EMPLOYEE('6','宇轩',null,'陈');
end;*/
--调用脚本_start
CREATE OR REPLACE procedure APPS.XXUPDATE_EMPLOYEE(I_EMPLOYEE_NUMBER varchar2,
I_FIRST_NAME varchar2 default null,
I_MIDDLE_NAMES varchar2 default null,
I_LAST_NAME varchar2 default null,
I_TITLE varchar2 default null,
I_KNOWN_AS varchar2 default null,
I_SEX varchar2 default null,
I_WORK_PHONE varchar2 default null,
I_EMAIL varchar2 default null) as
/*Author : Nolem , Create Date 2014/08/05:*/
/*
此函式,主要提供 更新已知員編(修正模式) 的相關欄位資訊,此程序只做更正,不會做版本變更及有效期間變更
I_EMPLOYEE_NUMBER 員編(必輸)
I_FIRST_NAME FIRST_NAME (可不輸入)
I_MIDDLE_NAMES MIDDLE_NAMES(可不輸入)
I_LAST_NAME LAST_NAME (可不輸入)
I_TITLE TITLE(可不輸入)
I_KNOWN_AS KNOWN_AS(可不輸入)
I_SEX SEX(可不輸入)
I_WORK_PHONE WORK_PHONE (可不輸入)
I_EMAIL EMAIL(可不輸入)
*/
-- Local Variables
-- -----------------------
lc_dt_ud_mode VARCHAR2(100) := NULL;
ln_assignment_id PER_ALL_ASSIGNMENTS_F.ASSIGNMENT_ID%TYPE := null;
lc_employee_rec PER_ALL_PEOPLE_F%ROWTYPE := null;
lc_employee_rec_init PER_ALL_PEOPLE_F%ROWTYPE := null;
-- Out Variables for Find Date Track Mode API
-- ----------------------------------------------------------------
lb_correction BOOLEAN;
lb_update BOOLEAN;
lb_update_override BOOLEAN;
lb_update_change_insert BOOLEAN;
-- Out Variables for Update Employee API
-- -----------------------------------------------------------
ld_effective_start_date DATE;
ld_effective_end_date DATE;
lb_name_combination_warning BOOLEAN;
lb_assign_payroll_warning BOOLEAN;
lb_orig_hire_warning BOOLEAN;
cursor cur is
select PERSON_ID,
EMPLOYEE_NUMBER,
EFFECTIVE_START_DATE,
EFFECTIVE_END_DATE,
PERSON_TYPE_ID,
FIRST_NAME,
LAST_NAME,
MIDDLE_NAMES,
FULL_NAME,
START_DATE,
COMMENT_ID,
EMAIL_ADDRESS,
HR_GENERAL.GET_PHONE_NUMBER(PERSON_ID,
'W1',
EFFECTIVE_START_DATE) WORK_TELEPHONE,
KNOWN_AS,
SEX,
TITLE,
OBJECT_VERSION_NUMBER,
ATTRIBUTE1,
ATTRIBUTE2,
ATTRIBUTE3,
ATTRIBUTE4,
ATTRIBUTE5,
ATTRIBUTE6,
ATTRIBUTE7,
ATTRIBUTE8,
ATTRIBUTE9,
ATTRIBUTE10,
ATTRIBUTE11,
ATTRIBUTE12,
ATTRIBUTE13,
ATTRIBUTE14,
ATTRIBUTE15
from PER_ALL_PEOPLE_F
where EMPLOYEE_NUMBER = I_EMPLOYEE_NUMBER;
BEGIN
for rec in cur loop
lc_employee_rec := lc_employee_rec_init;
begin
select ASSIGNMENT_ID
into ln_assignment_id
from PER_ALL_ASSIGNMENTS_F
where PERSON_ID = rec.PERSON_ID
and EFFECTIVE_START_DATE = rec.EFFECTIVE_START_DATE
and EFFECTIVE_END_DATE = rec.EFFECTIVE_END_DATE;
lc_employee_rec.object_version_number := rec.OBJECT_VERSION_NUMBER;
end;
-- Find Date Track Mode
-- --------------------------------
dt_api.find_dt_upd_modes( -- Input Data Elements
-- ------------------------------
p_effective_date => rec.EFFECTIVE_START_DATE,
p_base_table_name => 'PER_ALL_ASSIGNMENTS_F',
p_base_key_column => 'ASSIGNMENT_ID',
p_base_key_value => ln_assignment_id,
-- Output data elements
-- -------------------------------
p_correction => lb_correction,
p_update => lb_update,
p_update_override => lb_update_override,
p_update_change_insert => lb_update_change_insert);
IF (lb_update_override = TRUE OR lb_update_change_insert = TRUE) THEN
-- UPDATE_OVERRIDE
-- ---------------------------------
lc_dt_ud_mode := 'UPDATE_OVERRIDE';
END IF;
IF (lb_correction = TRUE) THEN
-- CORRECTION
-- ----------------------
lc_dt_ud_mode := 'CORRECTION';
END IF;
IF (lb_update = TRUE) THEN
-- UPDATE
-- --------------
lc_dt_ud_mode := 'UPDATE';
END IF;
--DBMS_OUTPUT.put_line (lc_dt_ud_mode || ' , ln_assignment_id=' || ln_assignment_id || ',ln_object_version_number='||ln_object_version_number || ',lc_employee_number='||lc_employee_number);
lc_employee_rec.employee_number := nvl(I_EMPLOYEE_NUMBER,
rec.EMPLOYEE_NUMBER);
lc_employee_rec.first_name := nvl(I_FIRST_NAME, rec.FIRST_NAME);
lc_employee_rec.middle_names := nvl(I_MIDDLE_NAMES, rec.MIDDLE_NAMES);
lc_employee_rec.last_name := nvl(I_LAST_NAME, rec.LAST_NAME);
lc_employee_rec.known_as := nvl(I_KNOWN_AS, rec.KNOWN_AS);
lc_employee_rec.title := nvl(I_TITLE, rec.TITLE);
lc_employee_rec.sex := nvl(I_SEX, rec.SEX);
lc_employee_rec.last_name := nvl(I_LAST_NAME, rec.LAST_NAME);
lc_employee_rec.work_telephone := nvl(I_WORK_PHONE, rec.WORK_TELEPHONE);
lc_employee_rec.email_address := nvl(I_EMAIL, rec.EMAIL_ADDRESS);
-- Update Employee API
-- ---------------------------------
hr_person_api.update_person( -- Input Data Elements
-- ------------------------------
p_effective_date => rec.EFFECTIVE_START_DATE,
p_datetrack_update_mode => lc_dt_ud_mode,
p_person_id => rec.person_id,
p_first_name => lc_employee_rec.first_name,
p_middle_names => lc_employee_rec.middle_names,
p_last_name => lc_employee_rec.last_name,
p_known_as => lc_employee_rec.known_as,
p_title => lc_employee_rec.title,
p_sex => lc_employee_rec.sex,
p_work_telephone => lc_employee_rec.work_telephone,
p_email_address => lc_employee_rec.email_address,
-- Output Data Elements
-- ----------------------------------
p_employee_number => lc_employee_rec.employee_number,
p_object_version_number => lc_employee_rec.object_version_number,
p_effective_start_date => ld_effective_start_date,
p_effective_end_date => ld_effective_end_date,
p_full_name => lc_employee_rec.full_name,
p_comment_id => lc_employee_rec.comment_id,
p_name_combination_warning => lb_name_combination_warning,
p_assign_payroll_warning => lb_assign_payroll_warning,
p_orig_hire_warning => lb_orig_hire_warning);
COMMIT;
end loop;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line(SQLERRM);
END;