ORA-01722: 无效的包编号
Posted
技术标签:
【中文标题】ORA-01722: 无效的包编号【英文标题】:ORA-01722: invalid number with package 【发布时间】:2016-02-18 11:13:45 【问题描述】:我看了很多帖子,但我仍然没有答案。
我之前运行脚本告诉 sql developer 充当发现者(已创建的包),但是在运行查询时它返回 ORA-01722: invalid number。
我从包中选择了对偶,它返回了值。
有人可以指出为什么它返回此错误消息的正确方向吗?
select gsb.name "Set of Books Name"
, gsb.set_of_books_id "Set of Books Id"
, gjb.name "Batch Name"
, gjh.name "Journal Name"
, trunc(gjh.date_created) "Journal Header Date Created"
, gjh.status "Journal Header Status"
, gcc.segment1 "Company"
, gcc.segment7 "Interco Code"
, APT.term_id "Term ID"
, APT.Name "Type of Term"
, APT.Description "Term Decription"
, ffvt3.description "Intercompany Descr"
, gcc.segment2 "Natural Account Code"
, ffvt.description "Natural Account Descr"
, gcc.segment3 "Cost Centre Code"
, ffvt2.description "Cost Centre Descr"
, gjl.je_line_num "Je Line Num"
, gjh.currency_code "Currency Code"
, gjl.description "Line Description"
, gjh.period_name "Period Name"
, gpd.period_num "Period Num"
, gpd.period_year "Period Year"
, gjc.user_je_category_name "Category Name"
, gjs.user_je_source_name "Source Name"
, gjl.status "Line Status"
, gjh.actual_flag "Actual Flag"
, nvl(gjl.accounted_dr,0) "Acctd Dr"
, nvl(gjl.accounted_cr,0) "Acctd Cr"
, trunc(gjh.posted_date) "GL Date"
, gjl.attribute3 "Recon Status"
, gjl.effective_date "Line GL Date"
, gjl.reference_1 "Reference1"
, gjl.reference_4 "Reference4"
, gjl.reference_2 "Invoice Id"
, pov.vendor_name "Vendor Name"
, pov.segment1 "Vendor Number"
, CASE
WHEN gjl.reference_6 = 'CUSTOMER'
THEN gjl.reference_4
ELSE gjl.reference_5
END "Invoice Num"
, gjh.doc_sequence_value "Doc Num"
, gjh.doc_sequence_value "Journal Voucher Num"
, api.invoice_date "Invoice Date"
, api.voucher_num "Image Num"
, api.discount_amount_taken "discount amount"
, api.attribute1 "PO Number"
, api.attribute2 "GRN Number"
, api.attribute3 "Invoice Approver"
, pvs.vendor_site_code "Vendor Site Code"
, gjl.code_combination_id "Code Combination Id"
, gcc.concatenated_segments "Full Account Code"
, api.amount_paid "Amount Paid"
, api.base_amount "Base Amount"
, api.creation_date "Creation Date"
, api.description "AP Inv Description"
, api.invoice_amount "Invoice Amount"
, api.invoice_type_lookup_code "Invoice Type"
, api.source "Invoice Source"
, gjh.posted_date "Posted Date"
, aca.check_date "Payment Date"
, aca.check_number "Payment Number"
, case when gjl.reference_6 = 'CUSTOMER' then gjl.reference_4
else null
end "Trans Number"
, case when gjl.reference_6 = 'CUSTOMER' then
(select distinct customer_name
from ar_customers_v
where customer_number = gjl.reference_5)
else null
end "Customer Name"
from gl_je_batches gjb
, gl_je_headers gjh
, gl_je_lines gjl
, gl_periods gpd
, gl_code_combinations_kfv gcc
, gl_sets_of_books gsb
, gl_je_categories_tl gjc
, gl_je_sources_tl gjs
, fnd_flex_value_sets ffvs
, fnd_flex_values ffv
, fnd_flex_values_tl ffvt
, fnd_flex_value_sets ffvs2
, fnd_flex_values ffv2
, fnd_flex_values_tl ffvt2
, fnd_flex_value_sets ffvs3
, fnd_flex_values ffv3
, fnd_flex_values_tl ffvt3
, ap_invoices_all api
, po_vendors pov
, po_vendor_sites_all pvs
, ap_invoice_payments_all aip
, ap_checks_all aca
, AP_TERMS_VL apt
where gjb.je_batch_id = gjh.je_batch_id
and gjh.je_header_id = gjl.je_header_id
and gjl.code_combination_id = gcc.code_combination_id
and gjc.je_category_name = gjh.je_category
and gjc.language = 'US'
and gjs.je_source_name = gjh.je_source
and gjs.language = 'US'
and ffvs.flex_value_set_id = ffv.flex_value_set_id
and ffvs.flex_value_set_name = XXASW_DISCO_UTIL_PKG.xxasw_get_gl_segment_fvs_name ('SEGMENT2')
and ffv.flex_value = gcc.segment2
and ffv.flex_value_id = ffvt.flex_value_id
and ffvt.language = 'US'
and ffvs2.flex_value_set_id = ffv2.flex_value_set_id
and ffvs2.flex_value_set_name = XXASW_DISCO_UTIL_PKG.xxasw_get_gl_segment_fvs_name ('SEGMENT3')
and ffv2.flex_value = gcc.segment3
and ffv2.flex_value_id = ffvt2.flex_value_id
and ffvt2.language = 'US'
and ffvs3.flex_value_set_id = ffv3.flex_value_set_id
and ffvs3.flex_value_set_name = XXASW_DISCO_UTIL_PKG.xxasw_get_gl_segment_fvs_name ('SEGMENT7')
and ffv3.flex_value = gcc.segment7
and ffv3.flex_value_id = ffvt3.flex_value_id
and ffvt3.language = 'US'
and gpd.period_name = gjh.period_name
and gpd.period_set_name = gsb.period_set_name
and gjh.set_of_books_id = gsb.set_of_books_id
and ((gjl.reference_9 <> 'TRADE_REC')
or (gjl.reference_9 is null))
and (case when gjl.reference_6 = 'AP Invoices'
then to_number(gjl.reference_2) else 0 end ) = api.invoice_id(+)
and gjl.reference_5 = api.invoice_num (+)
and pvs.vendor_id = pov.vendor_id (+)
and api.vendor_site_id = pvs.vendor_site_id (+)
and api.invoice_id = aip.invoice_id (+)
and aip.check_id = aca.check_id (+)
and api.terms_id = apt.term_id (+)
and ((aca.status_lookup_code = 'NEGOTIABLE')
or (aca.status_lookup_code is null))
and aip.reversal_inv_pmt_id(+) is null
and gcc.segment3 = 5221
and gjh.period_name = 'JAN-16'
and gcc.segment2 between 592712 and 592712
and gcc.segment3 between 0000 and 9999;
【问题讨论】:
一次删除5个项目,看看错误什么时候消失。 嗨,jarlh,我已经这样做了。它不起作用。正如下面的评论,我认为可能是这样,但事实并非如此...... 所以如果你只剩下一列和一张表,你的查询就不会运行?如果是这样的话,我会说那是问题专栏! 【参考方案1】:ORA-01722: 无效号码
当您尝试将字符串转换为数字时发生,但由于某种原因无法转换该字符串。
看起来您的查询中的罪魁祸首如下:
and (case when gjl.reference_6 = 'AP Invoices'
then to_number(gjl.reference_2) else 0 end ) = api.invoice_id(+)
这意味着gl_je_lines.reference_2
中存在数据问题,该列中存在您不期望的字符串值。
我将通过检查 select reference_2 from gl_je_lines
列中的数据并查看是否有任何明显会导致转换失败的内容来解决这个问题。
【讨论】:
嗨 lathonez,这是我最初的想法。但是当检查该列时,它没有任何异常。该列本身为空,但这就是使用“and (case when gjl.reference_6 = 'AP Invoices' then to_number(gjl.reference_2) else 0 end) = api.invoice_id(+)”的原因 看起来您是在使用 reference_6 = 'AP Invoices' 来推断 reference_2 不为空的事实?总是这样吗? 嗯,根据this,如果提供了 null,to_number 将返回 null,因此它不应该抛出该错误。 此表中并非总是有一些发票与联接的原因相连接...但是是的,它也返回空值,但这就是使用外部联接的原因。以上是关于ORA-01722: 无效的包编号的主要内容,如果未能解决你的问题,请参考以下文章