开发者

Insert Fail because of wrong non-numeric character

开发者 https://www.devze.com 2023-01-27 09:26 出处:网络
hy table: create table Players (PlayerNo number (4) not null, Name varchar2(15), date_of_birth date,leagno varchar(4));

hy

table:

create table Players (PlayerNo number (4) not null, Name varchar2(15), date_of_birth date,leagno varchar(4));

wrong insert:

insert into PLAYERS (PlayerNo,Name,date_of_birth,leagno) VALUES (1,'Philipp 开发者_如何学运维K','Jan-10-1999','1')

whats wrong?

error code:

Fehler beim Start in Zeile 1 in Befehl:
insert into PLAYERS (PlayerNo,Name,date_of_birth,leagno) VALUES (1,'Philipp K','Jan-10-1999','1')
Fehlerbericht:
SQL-Fehler: ORA-01858: Ein nicht-numerisches Zeichen wurde gefunden, während ein numerisches Zeichen erwartet wurde
01858. 00000 -  "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
           incorrect.  The input data did not contain a number where a number was
           required by the format model.
*Action:   Fix the input data or the date format model to make sure the
           elements match in number and type.  Then retry the operation.


*Cause: The input data to be converted using a date format model was incorrect. The input data did not contain a number where a number was required by the format model.

The date string you're using doesn't match what oracle is expecting. The default format, iirc, is DD-Mon-YYYY, not Mon-DD-YYYY as you're trying to use.


INSERT
INTO PLAYERS
  (
    PlayerNo,
    Name,
    date_of_birth,
    leagno
  )
  VALUES
  (
    1,
    'Philipp K',
    TO_DATE('Jan-10-1999','Mon-dd-yyyy'),
    '1'
  )

You need to supply date using TO_DATE with the right format.


The error explains:

"The input data to be converted using a date format model was incorrect. The input data did not contain a number where a number was required by the format model"

What this means is the value you are passing to the date_of_birth column is in the wrong format. By default Oracle expects dates to be in the format DD-MON-YYYY. You are passing a date in the format MON-DD-YYYY.

There are two - well three - ways of dealing with this.

  1. Use an explicit format mask: to_date('Jan-10-1999', 'MON-DD-YYYY')
  2. change the NLS_DATE_FORMAT parameter, at the session or even database level. Find out more here and here.
  3. change your insert statement to pass the date in the expected format.
0

精彩评论

暂无评论...
验证码 换一张
取 消