SQL error “ORA-01722: invalid number”

前端 未结 13 1777
野趣味
野趣味 2020-11-29 10:15

A very easy one for someone, The following insert is giving me the

ORA-01722: invalid number

why?

INSERT INTO C         


        
13条回答
  •  心在旅途
    2020-11-29 10:36

    Oracle does automatic String2number conversion, for String column values! However, for the textual comparisons in SQL, the input must be delimited as a String explicitly: The opposite conversion number2String is not performed automatically, not on the SQL-query level.

    I had this query:

    select max(acc_num) from ACCOUNTS where acc_num between 1001000 and 1001999;

    That one presented a problem: Error: ORA-01722: invalid number

    I have just surrounded the "numerical" values, to make them 'Strings', just making them explicitly delimited:

    select max(acc_num) from ACCOUNTS where acc_num between '1001000' and '1001999';

    ...and voilà: It returns the expected result.

    edit: And indeed: the col acc_num in my table is defined as String. Although not numerical, the invalid number was reported. And the explicit delimiting of the string-numbers resolved the problem.

    On the other hand, Oracle can treat Strings as numbers. So the numerical operations/functions can be applied on the Strings, and these queries work:

    select max(string_column) from TABLE;

    select string_column from TABLE where string_column between '2' and 'z';

    select string_column from TABLE where string_column > '1';

    select string_column from TABLE where string_column <= 'b';

提交回复
热议问题