The following lines contain the word 'select', 'insert', 'update' or 'delete':
-- Update Vendor Id and Vendor Site id with the Merged Vendor Id
-- and Vendor Site Id
-- If the Vendor Id and the Merged Vendor Id and in the same
-- agreement with the same vendor sites or no vendor sites and
-- if they have different priorities ,update the vendor ids
-- with the higher priority of the two
BEGIN
fun_net_util.Log_String(g_event_level,
l_path
,'Updating Netting Suppliers');
UPDATE fun_net_suppliers_all s
SET supplier_id = p_vendor_id,
supplier_site_id = decode(supplier_site_id,p_dup_vendor_site_id,
p_vendor_site_id, supplier_site_id)
WHERE supplier_id = p_dup_vendor_id
AND nvl(supplier_site_id, 0) =
decode(supplier_site_id, NULL,
0, p_dup_vendor_site_id);
,'Rows Updated'|| sql%rowcount);
UPDATE fun_net_suppliers_all s
SET supplier_priority = (
SELECT min(supplier_priority)
FROM fun_net_suppliers_all
WHERE agreement_id = s.agreement_id
AND supplier_id = s.supplier_id
AND nvl(supplier_site_id,0) =
decode(s.supplier_site_id,
NULL,0,s.supplier_site_id))
WHERE supplier_id = p_vendor_id
AND nvl(supplier_site_id, 0) =
decode(supplier_site_id, NULL,
0, p_vendor_site_id);
/* Delete the record that has the same agreement id, supplier priority , vendor and vendor site */
BEGIN
fun_net_util.Log_String(g_event_level,
l_path
,'Deleting Records');
DELETE FROM fun_net_suppliers_all s
WHERE netting_supplier_id = (SELECT min(netting_supplier_id)
FROM fun_net_suppliers_all
WHERE
s.agreement_id = agreement_id
AND s.supplier_id = supplier_id
AND nvl(s.supplier_site_id,0) = nvl(supplier_site_id,0)
AND s.supplier_priority = supplier_priority
GROUP BY agreement_id,
supplier_id,
supplier_site_id,
supplier_priority
HAVING COUNT(netting_supplier_id) > 1);
,'Records Deleted' || sql%rowcount);