ORA-01722: invalid number
Cause: The attempted conversion of a character string to a number failed because the character string was not a valid numeric literal. Only numeric fields or character fields containing numeric data may be used in arithmetic functions or expressions. Only numeric fields may be added to or subtracted from dates.
Action: Check the character strings in the function or expression. Check that they contain only numbers, a sign, a decimal point, and the character "E" or "e" and retry the operation.
ORA-01722 exception occurs when we explicitly or simplicity try to convert a character string to a number. This may occur while inserting/updating in number field is SQL. ORA-01722 also may occurs with comparison of string and number in sql.
SQL> select to_number('abc') from dual; select to_number('abc') from dual * ERROR at line 1: ORA-01722: invalid number
SQL> select * from dual where 'abc' < 100; select * from dual where 'abc' < 100 * ERROR at line 1: ORA-01722: invalid number
We can simply avoid ORA-01722 by following simple guidelines.
1. We should try to avoid implicit conversion.
2. We should compare with same datatypes.
3. While comparing different datatypes, we should first do explicit conversion.
4. We should not store numbers in varchar2 fields.
5. We should convert the expression to number before comparing it with number.
For checking the expression is number or not, you can use code provided in following post
- ORA-01460 unimplemented or unreasonable conversion requested
- ORA-00936 missing expression
- ORA-00911: invalid character
- ORA-00904: invalid identifier
- ORA-06502: PL/SQL: numeric or value errorstring