select from varchar2 column with numeric value sometimes gives invalid number error

Posted by Rene on Stack Overflow See other posts from Stack Overflow or by Rene
Published on 2010-05-11T06:57:03Z Indexed on 2010/05/11 7:24 UTC
Read the original article Hit count: 247

Filed under:
|

I'm trying to understand why, on some systems, I get an invalid number error message when I'm trying to select a value from a varchar2 column while on other systems I don't get the error while doing the exact same thing.

The table is something like this:

ID   Column_1  Column_2
 1         V     text
 2         D        1
 3         D        2
 4         D        3

and a query:

select ID
  from table
 where column_1='D'
   and column_2 = :some_number_value

:some_number_value is always numeric but can be null.

We've fixed the query:

select ID
  from table
 where column_1='D'
   and column_2 = to_char(:some_number_value)

This original query runs fine on most systems but on some systems gives an "invalid number" error. The question is why? Why does it work on most systems and not on some?

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about sql