ORA-01722: invalid number


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.

Reference: http://docs.oracle.com/cd/A58617_01/server.804/a58312/newch226.htm#18474

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.

Examples 1:
SQL> select to_number('abc') from dual;
select to_number('abc') from dual
                 *
ERROR at line 1:
ORA-01722: invalid number

Examples 2:
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
http://nimishgarg.blogspot.in/2010/03/oracle-function-isnumeric-check-value.html


Related Posts:
- 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

2 comments:

  1. select distinct number from tablename where dates=to_date(to_char('03-jul-13','dd-mon-yy'),'dd-mm-yy hh24:mi:ss')

    ReplyDelete
    Replies
    1. if your dates is date type then use following, use trunc if u need :)
      select distinct number from tablename where trunc(dates)=to_date('03-jul-13','dd-mon-yy')

      Delete