CREATE OR REPLACE PROCEDURE xxx_employee_qualification_p
IS
CURSOR get_details
IS
SELECT * FROM xxx_emp_qualification_t;
l_qualification_type_id NUMBER := NULL;
l_person_id NUMBER := NULL;
l_effective_date DATE := SYSDATE; --TO_DATE ('01-JAN-1950', 'DD-MON-YYYY');
l_qualification_id NUMBER := NULL;
l_object_version_number NUMBER := NULL;
l_err_msg VARCHAR2 (500) := NULL;
BEGIN
FOR fetch_details IN get_details
LOOP
-- Get Employee Person ID
BEGIN
SELECT person_id
INTO l_person_id
FROM per_people_x per
WHERE per.employee_number = fetch_details.employee_number;
EXCEPTION
WHEN OTHERS
THEN
l_err_msg := 'l_person_id not found !!!';
l_person_id := NULL;
END;
-- Get Qualification Type ID
BEGIN
SELECT qualification_type_id
INTO l_qualification_type_id
FROM per_qualification_types pq
WHERE UPPER (pq.name) = UPPER (fetch_details.qualification_type);
EXCEPTION
WHEN OTHERS
THEN
l_err_msg :=
l_err_msg
|| ' - '
|| 'l_qualification_type_id not found !!!';
l_qualification_type_id := NULL;
END;
IF l_person_id IS NOT NULL AND l_qualification_type_id IS NOT NULL
THEN
BEGIN
PER_QUALIFICATIONS_API.
CREATE_QUALIFICATION (
p_validate => FALSE,
p_effective_date => l_effective_date,
p_qualification_type_id => l_qualification_type_id,
p_business_group_id => fnd_profile.
VALUE (
'PER_BUSINESS_GROUP_ID'),
p_person_id => l_person_id,
p_title => fetch_details.
qualification_title,
p_qualification_id => l_qualification_id,
p_object_version_number => l_object_version_number);
UPDATE xxx_emp_qualification_t aeqt
SET aeqt.process_flag = 'Y', err_msg = NULL
WHERE aeqt.employee_number = fetch_details.employee_number;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_err_msg := SQLERRM;
UPDATE xxx_emp_qualification_t aeqt
SET aeqt.process_flag = 'N', err_msg = l_err_msg
WHERE aeqt.employee_number = fetch_details.employee_number;
COMMIT;
END;
ELSE
UPDATE xxx_emp_qualification_t aeqt
SET aeqt.process_flag = 'N', err_msg = l_err_msg
WHERE aeqt.employee_number = fetch_details.employee_number;
COMMIT;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
l_err_msg := SQLERRM;
DBMS_OUTPUT.put_line ('Main Exception: ' || l_err_msg);
END xxx_employee_qualification_p;
Very helpful.
ReplyDelete