因错误的非数字字符而插入失败

问题描述 投票:1回答:3

表:

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

插入错误:

insert into PLAYERS (PlayerNo,Name,date_of_birth,leagno) VALUES (1,'Philipp K','Jan-10-1999','1')

怎么了?

错误代码:

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.
sql oracle ora-01858
3个回答
2
投票

*原因:使用日期格式模型转换的输入数据不正确。输入数据不包含格式模型需要数字的数字。

您正在使用的日期字符串与oracle期望的字符串不匹配。默认格式iirc是DD-Mon-YYYY,而不是您尝试使用的Mon-DD-YYYY。


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

您需要使用正确的格式使用TO_DATE提供日期。


1
投票

该错误解释了:

“使用日期格式模型转换的输入数据不正确。输入数据不包含格式模型需要数字的数字”

这意味着您传递给date_of_birth列的值格式错误。默认情况下,Oracle期望日期采用DD-MON-YYYY格式。您将以MON-DD-YYYY格式传递日期。

有两种 - 三种 - 处理这种方法。

  1. 使用显式格式掩码:to_date('Jan-10-1999', 'MON-DD-YYYY')
  2. 在会话甚至数据库级别更改the NLS_DATE_FORMAT parameter。 Find out more here here
  3. 更改您的insert语句以传递预期格式的日期。
© www.soinside.com 2019 - 2024. All rights reserved.