I found this odd behavior and I’m breaking my brains with this… anyone has any ideas?
Oracle 10g:
I have two different tables, both have this column named “TESTCOL” as Varchar2(10), not nullable.
If I perform this query on table1, i get the proper results:
select * from table1 where TESTCOL = 1234;
Note that I’m specifically not placing ‘1234’… it’s not a typo, that’s a dynamic generated query and I will try not to change it (at least not in the near future).
But, if I run the same query, on table2, I get this error message:
ORA-01722: Invalid number
Both queries are run on the same session, same database.
I’ve been joining these two tables by that column and the join works ok, the only problem shows whenever I try to use that condition.
Any ideas on what could be different from one table to the other?
Thanks in advance.
If
TESTCOLcontains non-numbers, then Oracle might run into problems when convertingTESTCOLentries to numbers. Because, what it does internally, is this:If you’re so sure that
1234cannot be expressed as aVARCHARliteral, then try this instead, in order to compare varchar values, rather than numeric ones: