简体   繁体   中英

ERROR --> java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

I have an issue that is generated randomly (one time between thousandth of calls). The error ORA-01722: invalid number is generated in a random way while executing sql update in a prepared statement Oracle database.

Although i think my code is correct but then also it is showing error,So please tell me where i am wrong.

here is my code:

    select *
from 
(
select p.*, SD.GLORGANIZATION
from     EXT.INNOVA_STANDING_ORDER_PAYMENT p , EXT.STANDINGORDER_DEFINITION SD,PRM.PRM_CORP_STANDING_ORDER_DEF SOD
where    p.status=1 and p.transfersequence in (?) and p.sirano=? 
and p.paymentstatus in ( ? ) 
AND P.CORPORATION=SOD.INNOVACODE AND P.SERVICEINFO=SD.SUBSCRIBERNO AND SD.CORPORATECODE=SOD.CODE AND SD.ORDERSTATU IN ('22') AND SD.STATUS=1
AND P.DUEDATE=? and P.CORPORATION not in ('10000','203','500','501','405','213')
union all
select p.*, SD.GLORGANIZATION
from     EXT.INNOVA_STANDING_ORDER_PAYMENT p , EXT.STANDINGORDER_DEFINITION SD,PRM.PRM_CORP_STANDING_ORDER_DEF SOD
where    p.status=1 and p.transfersequence in (?) and p.sirano=? 
and p.paymentstatus in ( ? ) 
AND P.CORPORATION=SOD.INNOVACODE AND P.SERVICEINFO=SD.SUBSCRIBERNO2 || SD.SUBSCRIBERNO AND SD.CORPORATECODE=SOD.CODE AND SD.ORDERSTATU IN ('22') AND SD.STATUS=1
AND P.DUEDATE=? and P.CORPORATION  in ('203','213','221')
union all
select p.*, SD.GLORGANIZATION 
from     EXT.INNOVA_STANDING_ORDER_PAYMENT p , EXT.STANDINGORDER_DEFINITION SD,PRM.PRM_CORP_STANDING_ORDER_DEF SOD
where    p.status=1 and p.transfersequence in (?) and p.sirano=? 
and p.paymentstatus in ( ? ) 
AND P.CORPORATION=SOD.INNOVACODE AND P.SERVICEINFO=SD.SUBSCRIBERNO AND
P.CORPACCOUNTID=SD.CORPACCOUNTID AND
SD.CORPORATECODE=SOD.CODE AND SD.ORDERSTATU IN ('22') AND SD.STATUS=1
AND P.DUEDATE=? and P.CORPORATION  in ('500','501')
union all
select p.*, SD.GLORGANIZATION 
from     EXT.INNOVA_STANDING_ORDER_PAYMENT p , EXT.STANDINGORDER_DEFINITION SD,PRM.PRM_CORP_STANDING_ORDER_DEF SOD
where    p.status=1 and p.transfersequence in (?) and p.sirano=? 
and p.paymentstatus in ( ? ) 
AND P.CORPORATION=SOD.INNOVACODE AND P.SERVICEINFO=SD.SUBSCRIBERNO AND 
P.SERVICEINFO2=to_number(SD.SUBSCRIBERNO2) AND SD.CORPORATECODE=SOD.CODE AND SD.ORDERSTATU IN ('22') AND SD.STATUS=1
AND P.DUEDATE=? and P.CORPORATION  in ('405') AND SD.CORPORATECODE='405'
union all
select p.*, SD.GLORGANIZATION 
from ( SELECT iso.* 
FROM EXT.INNOVA_STANDING_ORDER_PAYMENT iso
WHERE iso.CORPORATION IN('10000')
ORDER BY iso.billnumber )p, EXT.STANDINGORDER_DEFINITION SD, PRM.PRM_CORP_STANDING_ORDER_DEF SOD
WHERE p.status = 1
AND P.CORPORATION = SOD.INNOVACODE
AND P.SERVICEINFO = SD.SUBSCRIBERNO
AND P.SERVICEINFO2 = TO_NUMBER( SD.SUBSCRIBERNO2 )
AND SD.CORPORATECODE = SOD.CODE
AND SD.ORDERSTATU IN('22')
AND SD.STATUS = 1
AND P.CORPORATION IN('10000'))q

"ORA-01722: invalid number" error may be raised during conversion varchar value to number. Typically, the problem usually occurs if you have '1,234' instead '1.234'.

For example:

select to_number('1,234') from dual;  -- ORA-01722 error 
select to_number('1.234') from dual;  -- correct 

For resolving your problem you need to check numeric data in query source tables.

Please also note, that conversion to number may be executed without to_number(). If you use an operation between 2 different data types, one of them may be implicitly converted to another data type.

For example

select * 
from some_table 
where name +1 = 2;

name is VARCHAR field and should be converted to type NUMBER for execution +1 operation. In query plan you will see TO_NUMBER() operation.

filter(TO_NUMBER("NAME")+1=2)

There are a lot of numbers in quotes like '405' in your query. Looks like you have VARCHAR type for numeric columns.

SD.CORPORATECODE='405' 

It may be a root cause of your problem, because you expect to have numbers in them, but may have any string in reality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM