The following lines contain the word 'select', 'insert', 'update' or 'delete':
FII_UTIL.Write_Log ('Inserted ' || SQL%ROWCOUNT || ' rows into fii_cost_center_grants.');
g_phase := 'Selecting top nodes for company and cost center dimensions from fii_financial_dimensions.';
select dbi_hier_top_node_id into l_company_top_node_id from fii_financial_dimensions where dimension_short_name='FII_COMPANIES';
select dbi_hier_top_node_id into l_cost_ctr_top_node_id from fii_financial_dimensions where dimension_short_name='HRI_CL_ORGCC';
g_phase := 'Inserting into fii_company_grants from bis_grants_v.';
INSERT INTO fii_company_grants
(user_id,
report_region_code,
company_id,
aggregated_flag,
last_update_date, last_updated_by,
creation_date, created_by, last_update_login)
(SELECT DISTINCT u.user_id,
s.report_region_code,
decode(s.granted_for,
-999, l_company_top_node_id,
s.granted_for),
h.aggregated_flag,
sysdate, g_fii_user_id,
sysdate, g_fii_user_id, g_fii_login_id
FROM bis_grants_v s, --user_security_initial2 s,
fii_com_pmv_agrt_nodes h,
fnd_user u
WHERE decode(s.granted_for,
-999, l_company_top_node_id,
s.granted_for) = h.company_id
AND s.delegation_parameter='FII_COMPANIES'
AND (sysdate BETWEEN TRUNC(s.start_date) AND nvl(TRUNC(s.end_date),to_date('12-31-9999','MM-DD-YYYY')))
AND s.granted_to = u.employee_id);
FII_UTIL.Write_Log ('Inserted ' || SQL%ROWCOUNT || ' rows into fii_company_grants.');
--DBMS_OUTPUT.PUT_LINE('Inserted ' || SQL%ROWCOUNT || ' rows into fii_company_grants.');
g_phase := 'Inserting into fii_cost_center_grants from bis_grants_v.';
INSERT INTO fii_cost_center_grants
(user_id,
report_region_code,
cost_center_id,
aggregated_flag,
last_update_date, last_updated_by,
creation_date, created_by, last_update_login)
(SELECT DISTINCT u.user_id,
s.report_region_code,
decode(s.granted_for,
-999, l_cost_ctr_top_node_id,
s.granted_for),
h.aggregated_flag,
sysdate, g_fii_user_id,
sysdate, g_fii_user_id, g_fii_login_id
FROM bis_grants_v s, --user_security_initial2 s,
fii_cc_pmv_agrt_nodes h,
fnd_user u
WHERE decode(s.granted_for,
-999, l_cost_ctr_top_node_id,
s.granted_for) = h.cost_center_id
AND s.delegation_parameter='HRI_CL_ORGCC'
AND (sysdate BETWEEN TRUNC(s.start_date) AND nvl(TRUNC(s.end_date),to_date('12-31-9999','MM-DD-YYYY')))
AND s.granted_to = u.employee_id);
FII_UTIL.Write_Log ('Inserted ' || SQL%ROWCOUNT || ' rows into fii_cost_center_grants.');
--DBMS_OUTPUT.PUT_LINE('Inserted ' || SQL%ROWCOUNT || ' rows into fii_cost_center_grants.');
DELETE FROM fii_company_grants
WHERE (user_id, report_region_code, company_id) IN
(SELECT s.user_id, s.report_region_code, s.company_id FROM fii_company_grants s, fii_company_hierarchies h
WHERE s.company_id = h.child_company_id
AND h.parent_company_id IN (SELECT company_id from fii_company_grants where user_id=s.user_id and report_region_code=s.report_region_code)
AND h.parent_company_id <> h.child_company_id);
FII_UTIL.Write_Log ('Deleted ' || SQL%ROWCOUNT || ' rows from fii_company_grants.');
--DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows from fii_company_grants.');
DELETE FROM fii_cost_center_grants
WHERE (user_id, report_region_code, cost_center_id) IN
(SELECT s.user_id, s.report_region_code, s.cost_center_id FROM fii_cost_center_grants s, fii_cost_ctr_hierarchies h
WHERE s.cost_center_id = h.child_cc_id
AND h.parent_cc_id IN (SELECT cost_center_id from fii_cost_center_grants where user_id=s.user_id and report_region_code=s.report_region_code)
AND h.parent_cc_id <> h.child_cc_id);
FII_UTIL.Write_Log ('Deleted ' || SQL%ROWCOUNT || ' rows from fii_cost_center_grants.');
--DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows from fii_cost_center_grants.');