I've a column field which is varchar and contains numbers and caracters entry all together.
MyColumn would contains those value for example :
"1.0", "AB", "A1", "1", "100"
If the user type "1" in my application field, I want to do a varchar search, matching "1" but also a "1.0".
I can't juste do a TO_NUMBER because there are data that are not a number and I would get a "not a number" exception.
I tried to use an OR clause checking if myColumn was a number before doing the cast to number :
(trim(TRANSLATE(myColumn,'0123456789', ' ')) is null and TO_NUMBER(myColumn) = 1.0)
or myColumn = '1.0'
But I still get ORA-01722: invalid number, since Oracle does not check one side of the AND clause before the other.
I tried to "case when" both side of the restriction :
case when trim(TRANSLATE(myColumn,'0123456789', ' ')) is null then TO_NUMBER(myColumn) else myColumn end
= case when trim(TRANSLATE(myColumn,'0123456789', ' ')) is null then 1.0 else '1.0' end;
But I get ORA-00932 inconsistent datatypes
Is there no way to do conditional where clause in oracle ?