问题:
/*vp是AR模块的收款、客户相关表(地点、账户、组织)、子分类账相关联的视图 */
条件1:AND vp.BILL_TO_CUSTOMER_ID = nvl(p_customer_id, vp.BILL_TO_CUSTOMER_ID)
条件2:AND (vp.BILL_TO_CUSTOMER_ID = p_customer_id OR p_customer_id IS NULL)
PL/SQL环境中,上面两个条件是等价的吗?
答案:
有其他表关联的条件下,不是等价的,因为 收款上没有客户ID,只有地点id,通过地点id关联相关表取得客户id,这种间接关联的是不等价的。
视图如下,此视图是从AR模块追溯到子分类账
CREATE OR REPLACE VIEW CUX_AR_ALL_SLA_V AS
SELECT CT.ORG_ID,
ct.trx_number,
CT.BILL_TO_CUSTOMER_ID,
h.accounting_date gl_date,
h.period_name,
l.entered_dr,
l.entered_cr,
l.accounted_dr,
l.accounted_cr,
l.code_combination_id,
ct.attribute1,
ct.attribute2,
TE.ENTITY_CODE,
h.ledger_id
FROM xla.xla_ae_headers h,
xla.xla_ae_lines l,
xla.xla_events e,
xla.xla_transaction_entities te,
ra_customer_trx_all ct
WHERE h.application_id = l.application_id
AND h.ae_header_id = l.ae_header_id
AND h.application_id = e.application_id
AND h.event_id = e.event_id
AND h.application_id = te.application_id
AND h.entity_id = te.entity_id
AND te.application_id = 222
AND te.entity_code = 'TRANSACTIONS'
AND nvl(te.source_id_int_1, (-99)) = ct.customer_trx_id
AND h.gl_transfer_status_code = 'Y'
UNION ALL
-- 收款、核销、杂项收款
SELECT CR.ORG_ID,
cr.receipt_number,
hca.cust_account_id,
h.accounting_date gl_date,
h.period_name,
l.entered_dr,
l.entered_cr,
l.accounted_dr,
l.accounted_cr,
l.code_combination_id,
cr.attribute1,
cr.attribute2,
te.entity_code,
h.ledger_id
FROM xla.xla_ae_headers h,
xla.xla_ae_lines l,
xla.xla_events e,
xla.xla_transaction_entities te,
ar_cash_receipts_all cr,
hz_parties hp, --客户组织表
hz_cust_accounts hca, --客户表
hz_cust_acct_sites_all hcas, --客户地点表
hz_cust_site_uses_all hcs --客户地点用图表
WHERE h.application_id = l.application_id
AND h.ae_header_id = l.ae_header_id
AND h.application_id = e.application_id
AND h.event_id = e.event_id
AND h.application_id = te.application_id
AND h.entity_id = te.entity_id
AND te.application_id = 222
AND te.ledger_id = 2022
AND te.entity_code = 'RECEIPTS'
AND nvl(te.source_id_int_1, -99) = cr.cash_receipt_id
AND hcs.site_use_id = cr.customer_site_use_id
AND hca.party_id = hp.party_id
AND hca.cust_account_id = hcas.cust_account_id
AND hcas.cust_acct_site_id = hcs.cust_acct_site_id
AND hp.attribute_category = 'CUSTOMER'
AND h.gl_transfer_status_code = 'Y'
UNION ALL
-- ADJUSTMENTS
SELECT ADJ.ORG_ID,
ct.trx_number,
ct.bill_to_customer_id,
h.accounting_date gl_date,
h.period_name,
l.entered_dr,
l.entered_cr,
l.accounted_dr,
l.accounted_cr,
l.code_combination_id,
ct.attribute1,
ct.attribute2,
te.entity_code,
h.ledger_id
FROM xla.xla_ae_headers h,
xla.xla_ae_lines l,
xla.xla_events e,
xla.xla_transaction_entities te,
ar_adjustments_all adj,
ra_customer_trx_all ct
WHERE h.application_id = l.application_id
AND h.ae_header_id = l.ae_header_id
AND h.application_id = e.application_id
AND h.event_id = e.event_id
AND h.application_id = te.application_id
AND h.entity_id = te.entity_id
AND te.application_id = 222
AND te.entity_code = 'ADJUSTMENTS'
AND nvl(te.source_id_int_1, (-99)) = adj.adjustment_id
AND adj.customer_trx_id = ct.customer_trx_id
AND h.gl_transfer_status_code = 'Y'
;