The following lines contain the word 'select', 'insert', 'update' or 'delete':
SELECT COUNT(1)
INTO ln_count
FROM AP_HOLDS ah
WHERE ah.invoice_id = p_invoice_id
AND NVL(ah.status_flag,'X') <> 'R'; --Added the Condition Based on the Bug 6473102
SELECT MAX(AVPFPV.accounting_date)
INTO ld_settlement_date
FROM ap_view_prepays_fr_prepay_v AVPFPV
WHERE AVPFPV.prepay_id = p_invoice_id
AND AVPFPV.prepay_line_number = p_line_number;
SELECT DISTINCT ffv.description
INTO v_value_desc
FROM gl_code_combinations gcc
,fnd_id_flex_structures ffs
,fnd_id_flex_segments fseg
,fnd_flex_values_vl ffv
WHERE gcc.chart_of_accounts_id = ffs.id_flex_num
AND ffs.id_flex_num = fseg.id_flex_num
AND ffs.id_flex_code = fseg.id_flex_code
AND fseg.application_column_name = p_seg_type
AND fseg.flex_value_set_id = ffv.flex_value_set_id
AND ffs.id_flex_code = 'GL#'
AND gcc.chart_of_accounts_id = (SELECT chart_of_accounts_id
FROM gl_access_sets
WHERE access_set_id = fnd_profile.value('GL_ACCESS_SET_ID'))
AND ffv.flex_value = p_seg_value;
SELECT ffv.description
INTO v_value_desc
FROM fnd_descr_flex_col_usage_vl fdfcu
,fnd_flex_values_vl ffv
WHERE fdfcu.flex_value_set_id = ffv.flex_value_set_id
AND fdfcu.application_id = 200
AND fdfcu.descriptive_flexfield_name = 'AP_INVOICES'
AND fdfcu.descriptive_flex_context_code ='Global Data Elements'
AND fdfcu.application_column_name = p_seg_type
AND ffv.flex_value = p_seg_value;
SELECT gled.name
INTO gc_ledger_name
FROM gl_ledgers gled
,gl_access_set_norm_assign gasna
WHERE gasna.access_set_id = FND_PROFILE.VALUE('GL_ACCESS_SET_ID')
AND gled.ledger_id = gasna.ledger_id
AND gled.ledger_category_code = 'PRIMARY';
SELECT gps.start_date
INTO ld_period_from_date
FROM gl_period_statuses gps
WHERE gps.period_name = PERIOD_FROM_PARAM
AND gps.application_id = 200
AND gps.set_of_books_id = FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
SELECT gps.end_date
INTO ld_period_to_date
FROM gl_period_statuses gps
WHERE gps.period_name = PERIOD_TO_PARAM
AND gps.application_id = 200
AND gps.set_of_books_id = FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
gc_select_clause := ' gjh.status ';
' ,(SELECT avprpv.org_id org_id
,avprpv.prepay_id prepay_id
,avprpv.prepay_line_number prepay_line_number
,avprpv.prepay_amount_applied prepay_amount_applied
FROM ap_view_prepays_fr_prepay_v avprpv
WHERE NVL(avprpv.accounting_date,:gd_from_date) <= :gd_from_date) avprpv ';
SELECT NVL(sum(NVL(xdl.unrounded_ENTERED_dR,0)-NVL(xdl.unrounded_entered_cr,0)),0)
INTO ln_inv_amt_ent
FROM ap_invoices ai
,ap_invoice_distributions aid
,ap_invoice_distributions aidinv
,ap_invoices aiinv
,xla_events xe
,xla_ae_lines xal
,xla_distribution_links xdl
WHERE ai.invoice_id=p_invoice_id
AND ai.invoice_date <= p_inv_date
AND aid.invoice_id=ai.invoice_id
AND aid.line_type_lookup_code='ITEM'
AND aidinv.prepay_distribution_id=aid.invoice_distribution_id
AND aiinv.invoice_id=aidinv.invoice_id
AND xe.event_type_code IN ('PREPAYMENT APPLIED','PREPAYMENT UNAPPLIED')
AND xe.event_id=xdl.event_id
AND xdl.event_id=aidinv.accounting_event_id
AND xal.ae_header_id=xdl.ae_header_id
AND xal.ae_line_num=xdl.ae_line_num
AND xal.accounting_class_code='LIABILITY'
AND xe.application_id=200
AND xdl.application_id=200
AND xal.application_id=200;