The following lines contain the word 'select', 'insert', 'update' or 'delete':
SELECT air.original_invoice_id, air.checkrun_name
FROM ap_invoice_relationships air,
ap_invoices api,
fv_terms_types fvt
WHERE( air.original_invoice_id NOT IN
(SELECT farc.invoice_id
FROM fv_assign_reason_codes farc
WHERE farc.set_of_books_id = x_set_of_books_id
AND org_id = x_org_id
AND farc.checkrun_name is not null -- Bug 5037297
AND entry_source = 'INTEREST')
OR
(air.original_invoice_id IN
(SELECT farc.invoice_id
FROM fv_assign_reason_codes farc
WHERE farc.set_of_books_id = x_set_of_books_id
AND org_id = x_org_id
AND entry_source = 'INTEREST'
AND air.checkrun_name <> farc.checkrun_name)))
AND api.org_id = x_org_id
AND air.original_invoice_id = api.invoice_id
AND fvt.term_id = api.terms_id
AND fvt.terms_type = 'PROMPT PAY';
UPDATE fv_assign_reason_codes
SET checkrun_name = reason_code_rec.checkrun_name,
entry_mode = 'SYSTEM',
last_update_date = SYSDATE,
last_updated_by = FND_GLOBAL.USER_ID,
last_update_login = FND_GLOBAL.LOGIN_ID
WHERE invoice_id = reason_code_rec.original_invoice_id
AND org_id = x_org_id
AND set_of_books_id = x_set_of_books_id
AND entry_source = 'INTEREST';
INSERT INTO fv_assign_reason_codes
(invoice_id,
org_id,
set_of_books_id,
entry_mode,
entry_source,
last_update_date,
last_updated_by,
created_by,
creation_date,
checkrun_name,
last_update_login)
VALUES
(reason_code_rec.original_invoice_id,
x_org_id,
x_set_of_books_id,
'SYSTEM',
'INTEREST',
SYSDATE,
FND_GLOBAL.USER_ID,
FND_GLOBAL.USER_ID,
SYSDATE,
reason_code_rec.checkrun_name,
FND_GLOBAL.LOGIN_ID);
SELECT /*+ USE_MERGE(api) */ api.invoice_id, apc.checkrun_name
FROM fv_terms_types ftt,
ap_terms apt,
ap_invoices api,
ap_checks apc,
ap_invoice_payments app
WHERE app.set_of_books_id = x_set_of_books_id
and api.org_id = x_org_id
and app.discount_lost > 0
and api.invoice_id = app.invoice_id
and apc.check_id = app.check_id
and apc.checkrun_name like '%Quick Payment%'
AND apt.term_id = api.terms_id
AND ftt.term_id = apt.term_id
AND ftt.terms_type = 'PROMPT PAY'
AND apc.void_date is null;
select count (*)
into v_count
from fv_assign_reason_codes fvr
where fvr.invoice_id = v_quick_payments.invoice_id
and org_id = x_org_id
and fvr.entry_source = 'EBD'
and fvr.set_of_books_id = x_set_of_books_id;
UPDATE fv_assign_reason_codes
SET Checkrun_name = v_quick_payments.checkrun_name,
Entry_mode = 'SYSTEM',
Last_Update_Date = SYSDATE,
Last_Updated_By = FND_GLOBAL.USER_ID,
Last_Update_Login = FND_GLOBAL.LOGIN_ID
where invoice_id = v_quick_payments.invoice_id
and set_of_books_id = x_set_of_books_id
and org_id = x_org_id
and entry_source = 'EBD';
INSERT into fv_assign_reason_codes
(invoice_id, entry_source, set_of_books_id,
/*-- Version 1.1 RCW.--------*/
org_id,
/*-- end 1.1 RCW -----------*/
entry_mode, last_update_date,
last_updated_by, created_by, creation_date, checkrun_name, last_update_login)
VALUES
(v_quick_payments.invoice_id, 'EBD', x_set_of_books_id,
/*-- Version 1.1 RCW.-------*/
x_org_id,
/*-- end 1.1 RCW ----------*/
'SYSTEM', sysdate,
fnd_global.user_id, fnd_global.user_id, sysdate,
v_quick_payments.checkrun_name, fnd_global.login_id);