在特定日期范围内接收 ORA-01427
Posted
技术标签:
【中文标题】在特定日期范围内接收 ORA-01427【英文标题】:Receiving ORA-01427 in specific date ranges 【发布时间】:2021-01-26 15:25:19 【问题描述】:我有一个在不同日期范围内返回 ORA-01427 的 ORACLE BIP 查询。我不理解该错误,并相信我已将其缩小到特定的行。我相信我的子查询.....(select Distinct DISPLAYED_FIELD FROM AP_LOOKUP_CODES where lookup_type = 'AP_ACCOUNTING_STATUS' and lookup_code = AP_INVOICES_UTILITY_PKG.GET_ACCOUNTING_STATUS(a.INVOICE_ID)FETCH FIRST 1 ROWS ONLY) AS ACCOUNTING_STATUS
,...正在抛出错误。我尝试了各种修复,但似乎没有任何解决问题的方法。包括使用 In 条件或 ROWNUM 但没有成功。我的目标是让任何日期范围返回而不会出现错误。我知道我正在工作的空间最近是从另一个环境克隆的
Select a.invoice_id, a.invoice_num,
to_char(a.invoice_date,'MM/DD/YYYY'),
to_char(a.terms_date,'MM/DD/YYYY'), a.invoice_currency_code, a.invoice_amount, n.vendor_name, s.vendor_site_code ,c.title, c.description, prf.name as Entity, bus.Bu_Name,
to_char(d.creation_date,'MM/DD/YYYY'), d.Category_Name,
Case When to_number(c.dm_version_number) is null Then p.did Else to_number(c.dm_version_number) End
document_id,
doc.datatype_code,
(select distinct to_char(b.accounting_date,'MM/DD/YYYY') from ap_invoice_distributions_all b where a.invoice_id = b.invoice_id ) as accounting_date,
(select Distinct DISPLAYED_FIELD FROM AP_LOOKUP_CODES where lookup_type = 'AP_ACCOUNTING_STATUS' and lookup_code = AP_INVOICES_UTILITY_PKG.GET_ACCOUNTING_STATUS(a.INVOICE_ID)FETCH FIRST 1 ROWS ONLY) AS ACCOUNTING_STATUS,
(SELECT DISPLAYED_FIELD FROM AP_LOOKUP_CODES WHERE LOOKUP_TYPE = 'INVOICE PAYMENT STATUS'
AND LOOKUP_CODE = a.PAYMENT_STATUS_FLAG) AS PAYMENT_STATUS
from ap_invoices_all a,poz_supplier_sites_v s, poz_suppliers_v n, fnd_attached_documents d ,fnd_documents_tl c , revisions p, xle_entity_profiles prf, fun_all_business_units_v bus, fnd_documents doc
where a.vendor_id = s.vendor_id
and a.vendor_site_id = s.vendor_site_id
and a.party_site_id = s.party_site_id
and a.vendor_id = n.vendor_id
and a.party_id = n.party_id
and d.pk1_value = a.invoice_id
and d.entity_name = 'AP_INVOICES_ALL'
and d.document_id = c.document_id
and c.document_id = doc.document_id
and a.legal_entity_id = prf.legal_entity_id
and a.legal_entity_id = bus.legal_entity_id
and substr(a.image_document_num,3) = p.ddocname
and (n.vendor_name in (:Supplier) or 'All' in (:Supplier || 'All'))
and (prf.name in (:Legal_Entity) or 'All' in (:Legal_Entity || 'All'))
and (a.invoice_currency_code in (:Currency) or 'All' in (:Currency ||'All'))
and (bus.bu_name in (:Business_Unit) or 'All' in (:Business_Unit ||'All'))
and (( a.invoice_num = :Invoice_Number AND :Invoice_Number is not null)
or (1 = 1 and :Invoice_Number is null) )
And ((CASE WHEN :Date_Type = 'Invoice Date' Then a.invoice_date WHEN :Date_Type = 'Accounting Date' Then a.gl_date WHEN :Date_Type = 'Invoice Received Date' Then a.terms_date END) between :Start_Date and :End_Date)
And (((Case when :Amount_Range = 1 Then a.invoice_amount END) between 0 and 5000 )
or ((Case when :Amount_Range = 2 Then a.invoice_amount END) between 5001 and 50000 )
or ((Case when :Amount_Range = 3 Then a.invoice_amount END) between 50001 and 999999 )
or ((Case when :Amount_Range = 4 Then a.invoice_amount END) > 1000000 )
or (1=1 and :Amount_Range = 0))
order by a.invoice_id
【问题讨论】:
您可以排除SELECT
中的每个子查询以查找该字段,然后通过连接键在子查询分组中使用的表中进行计数,然后决定如何管理多个值。我认为您需要为发票选择一个会计日期,并且由于ap_invoice_distributions_all
每张发票包含多行,如何选择一个日期取决于您:An invoice can have multiple distributions
、dosc says。将代码转换为值的查找看起来不错。
【参考方案1】:
您只需要给定查询中的任何记录,然后使用max
而不使用group by
,如下所示:
(select max(DISPLAYED_FIELD)
FROM AP_LOOKUP_CODES
where lookup_type = 'AP_ACCOUNTING_STATUS'
and lookup_code = AP_INVOICES_UTILITY_PKG.GET_ACCOUNTING_STATUS(a.INVOICE_ID)
) AS ACCOUNTING_STATUS
【讨论】:
此更改在各种日期范围内仍然返回 ORA-01427 错误,而在其他日期范围内工作正常。任何其他后端问题是否会导致此错误。我知道我正在工作的空间最近是从另一个环境克隆的。以上是关于在特定日期范围内接收 ORA-01427的主要内容,如果未能解决你的问题,请参考以下文章