Search code examples
sqloracle-databaseora-01722

ORA-01722- Invalid Number


I have a query in the package throwing error

ORA-01722 : invalid number.

I tried many ways but no luck.

select h.column  
  from table1 h,table2 c 
 where c.created_date='17-MAY-17' 
   and nvl(c.acct_nmbr,0)=nvl(to_number(h.v_acct_num),0) 
  • c.acct_nmbr is of NUMBER(19,0)
  • h.v_acct_num is of varchar2(4000 byte)

Please suggest me the solution


Solution

  • Obviously v_acct_num column contains non-numeric values. to_number() function has restriction that the value in the argument shouldn't contain any non-numeric character, otherwise the system hurls with ORA-01722 : invalid number. If you're sure about the data matches when non-numeric characters are extracted then use regexp_replace(t2.v_acct_num,'[^[:digit:]]') within the collation of the join's on clause :

    select t2.column  
      from table1 t1
      join table2 t2 on nvl(t1.acct_nmbr,0) = nvl(regexp_replace(t2.v_acct_num,'[^[:digit:]]'),0)
     where t2.created_date = date'2017-05-17'
    

    Use ANSI-92 standard for Join, and ISO-8601 standard for date syntaxes.