DECLARE
p_effective_date DATE;
p_object_version_number NUMBER;
p_duplicate_org_warning BOOLEAN;
v_err VARCHAR2 (1000);
CURSOR c1
IS
(SELECT *
FROM xx_update_org_cost_center_nol xx
WHERE xx.valid_flag = 'N' AND xx.org_id IS NOT NULL)
FOR UPDATE;
v_c1 c1%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1
INTO v_c1;
EXIT WHEN c1%NOTFOUND;
BEGIN
SELECT org.date_from, org.object_version_number
INTO p_effective_date, p_object_version_number
FROM hr_all_organization_units org
WHERE org.business_group_id = v_c1.business_group_id
AND org.organization_id = v_c1.org_id;
BEGIN
hr_organization_api.update_organization
(p_validate => FALSE,
p_effective_date => p_effective_date,
p_organization_id => v_c1.org_id,
p_segment2 => TO_CHAR
(v_c1.cost_center),
p_object_version_number => p_object_version_number,
p_duplicate_org_warning => p_duplicate_org_warning
);
UPDATE xx_update_org_cost_center_nol xx
SET xx.err = 'Done',
xx.valid_flag = 'Y'
WHERE CURRENT OF c1;
EXCEPTION
WHEN OTHERS
THEN
p_effective_date := NULL;
p_object_version_number := NULL;
p_duplicate_org_warning := NULL;
v_err := NULL;
v_err := (SQLERRM);
UPDATE xx_update_org_cost_center_nol xx
SET xx.err = v_err,
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
EXCEPTION
WHEN OTHERS
THEN
p_effective_date := NULL;
p_object_version_number := NULL;
p_duplicate_org_warning := NULL;
v_err := NULL;
UPDATE xx_update_org_cost_center_nol xx
SET xx.err = 'Organization Select Error',
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
END LOOP;
CLOSE c1;
COMMIT;
END;
p_effective_date DATE;
p_object_version_number NUMBER;
p_duplicate_org_warning BOOLEAN;
v_err VARCHAR2 (1000);
CURSOR c1
IS
(SELECT *
FROM xx_update_org_cost_center_nol xx
WHERE xx.valid_flag = 'N' AND xx.org_id IS NOT NULL)
FOR UPDATE;
v_c1 c1%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1
INTO v_c1;
EXIT WHEN c1%NOTFOUND;
BEGIN
SELECT org.date_from, org.object_version_number
INTO p_effective_date, p_object_version_number
FROM hr_all_organization_units org
WHERE org.business_group_id = v_c1.business_group_id
AND org.organization_id = v_c1.org_id;
BEGIN
hr_organization_api.update_organization
(p_validate => FALSE,
p_effective_date => p_effective_date,
p_organization_id => v_c1.org_id,
p_segment2 => TO_CHAR
(v_c1.cost_center),
p_object_version_number => p_object_version_number,
p_duplicate_org_warning => p_duplicate_org_warning
);
UPDATE xx_update_org_cost_center_nol xx
SET xx.err = 'Done',
xx.valid_flag = 'Y'
WHERE CURRENT OF c1;
EXCEPTION
WHEN OTHERS
THEN
p_effective_date := NULL;
p_object_version_number := NULL;
p_duplicate_org_warning := NULL;
v_err := NULL;
v_err := (SQLERRM);
UPDATE xx_update_org_cost_center_nol xx
SET xx.err = v_err,
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
EXCEPTION
WHEN OTHERS
THEN
p_effective_date := NULL;
p_object_version_number := NULL;
p_duplicate_org_warning := NULL;
v_err := NULL;
UPDATE xx_update_org_cost_center_nol xx
SET xx.err = 'Organization Select Error',
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
END LOOP;
CLOSE c1;
COMMIT;
END;