We have a SQL query which has a condition like below.
result_value <> 0
The result_value is a varchar column in our Oracle EBS database. The query works fine most of the time. But randomly it throws this below error.
[Error] Execution (216: 33): ORA-01722: invalid number
Changing the condition result_value <> TO_CHAR ('0') makes it work when it errors out.
Any reason why the system behaves like this? Below is a screenshot of the result. The alphanumeric column is a result of regexp_like(result_value , '^-?\d+(.\d+)?$(E(+|-)\d+)?$') then 'numeric' else 'alpha' end alphanumeric

From Oracle 12, you can use
TO_NUMBER(result_value DEFAULT NULL ON CONVERSION ERROR)and then you can compare to a number and may not need the regular expression:Which, for the sample data:
Outputs:
Note: using
result_value <> '0'would only exclude one of row of the sample data when there are actually 5 rows with the numeric value identical to0.fiddle