SQL error “ORA-01722: invalid number”

前端 未结 13 1654
野趣味
野趣味 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:21

    This is because:

    You executed an SQL statement that tried to convert a string to a number, but it was unsuccessful.

    As explained in:

    • Oracle/PLSQL: ORA-01722 Error.

    To resolve this error:

    Only numeric fields or character fields that contain numeric values can be used in arithmetic operations. Make sure that all expressions evaluate to numbers.

    0 讨论(0)
  • 2020-11-29 10:23

    try this as well, when you have a invalid number error

    In this a.emplid is number and b.emplid is an varchar2 so if you got to convert one of the sides

    where to_char(a.emplid)=b.emplid

    0 讨论(0)
  • 2020-11-29 10:24

    Well it also can be :

    SELECT t.col1, t.col2, ('test' + t.col3) as test_col3 
    FROM table t;
    

    where for concatenation in oracle is used the operator || not +.

    In this case you get : ORA-01722: invalid number ...

    0 讨论(0)
  • 2020-11-29 10:26

    As this error comes when you are trying to insert non-numeric value into a numeric column in db it seems that your last field might be numeric and you are trying to send it as a string in database. check your last value.

    0 讨论(0)
  • 2020-11-29 10:29

    Here's one way to solve it. Remove non-numeric characters then cast it as a number.

    cast(regexp_replace('0419 853 694', '[^0-9]+', '') as number)
    
    0 讨论(0)
  • 2020-11-29 10:29

    This happened to me too, but the problem was actually different: file encoding.

    The file was correct, but the file encoding was wrong. It was generated by the export utility of SQL Server and I saved it as Unicode.

    The file itself looked good in the text editor, but when I opened the *.bad file that the SQL*loader generated with the rejected lines, I saw it had bad characters between every original character. Then I though about the encoding.

    I opened the original file with Notepad++ and converted it to ANSI, and everything loaded properly.

    0 讨论(0)
提交回复
热议问题