简体   繁体   中英

ORA-01858: a non-numeric character was found where a numeric was expected? Even when the values are numbers?

This is the table

    CREATE TABLE Employee
    (EmpID number(5) primary key,
    SIN Number(9) Not null,
    LastName Varchar2(25) Not null,
    FirstName Varchar2(25),
    Street Varchar2(30),
    City Varchar2(25),
    Province Char(2),
    PostalCode Varchar2(7),
    JobCode Number(4) Not null,
    Foreign Key(JobCode) REFERENCES Job,
    IncomeTax Char(1),
    BirthDate Date,
    HireDate Date,
    JobCodeDate Date)
    TABLESPACE users;

This is the line I am trying to insert, there is only three numeric values and all of them are numbers as far as I can see.

INSERT INTO Employee VALUES(97319,516303417,'Novak','Gerry','6803 Park Ave.','Moose Jaw','SK','S6H 1X7',3000,'N','24-Aug-86','07-Jul-03','07-Jul-03');

ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected

I believe the issue is with the date columns try using this syntax to_date('07-Jul-03','DD-MON-YY') :

INSERT INTO Employee 
VALUES(97319,516303417,'Novak','Gerry','6803 Park Ave.','Moose Jaw','SK','S6H 1X7',3000,'N',to_date('24-Aug-86', 'DD-MON-YY'),to_date('07-Jul-03','DD-MON-YY'),to_date('07-Jul-03','DD-MON-YY'));

SQL-Fiddle: http://sqlfiddle.com/#!4/0e9df/2

alter SESSION set NLS_DATE_FORMAT = 'DD-Mon-YY';

我只需输入此内容,以便sql将正确执行插入查询中的日期格式

There's possibly a discrepancy between the order of fields as laid out in the INSERT statement, and the order that Oracle is expecting them. I suggest trying again using the full syntax of the INSERT (ie specify field names when doing the INSERT). That way, it's absolutely clear the value to field correlation being made.

So something like this:

INSERT 
INTO Employee (EmpID, SIN, LastName, FirstName, Street, City, Province, PostalCode, JobCode, IncomeTax, BirthDate, HireDate, JobCodeDate)
VALUES(97319,516303417,'Novak','Gerry','6803 Park Ave.','Moose Jaw','SK','S6H 1X7',3000,'N','1986-08-24','2003-07-07','2003-07-07');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM