0

我必须创建一个表并将值插入表中。正在创建表,但它不会插入值。这是我的代码-

CREATE TABLE CUSTOMER(
CID         number(20) not null primary key,        
FNAME       varchar2(50) not null,                  
MIDDLE      varchar2(50) null,
LNAME       varchar2(50) not null,
STREET      varchar2(50) not null,
CITY        varchar2(50) not null,
STATE       char(2) not null,
ZIP         varchar2(5) not null,
PHONE       varchar2(20) not null,
BIRTH_YR    date);

INSERT INTO CUSTOMER VALUES(
'1','john','paul','connor','Broad st','newark','nj','07103','2018643110','1992');

我不断收到错误

[Error] Script lines: 12-14 ------------------------
ORA-01861: literal does not match format string
Script line 14, statement line 2, column 85 

有人可以帮帮我吗?我究竟做错了什么?

4

2 回答 2

3

您必须将表定义更改为如下所示,以允许以您需要的格式插入年份:

CREATE TABLE CUSTOMER(
CID         number(20) not null primary key,        
FNAME       varchar2(50) not null,                  
MIDDLE      varchar2(50) null,
LNAME       varchar2(50) not null,
STREET      varchar2(50) not null,
CITY        varchar2(50) not null,
STATE       char(2) not null,
ZIP         varchar2(5) not null,
PHONE       varchar2(20) not null,
BIRTH_YR    char(4) not null);

否则,您必须以 Oracle 数据库接受的默认格式提供文字日期值。您可以使用此查询来找出系统接受的日期格式:

SELECT *
FROM nls_database_parameters
WHERE parameter LIKE '%DATE%'

对我来说,它返回:

NLS_DATE_FORMAT      |   DD-MON-RR
---------------------------------
NLS_DATE_LANGUAGE    |   AMERICAN

'01-Jan-1992'这意味着我应该在列中插入值,而不是“1992” BIRTH_YR

INSERT INTO CUSTOMER
    VALUES('1','john','paul','connor','Broad st','newark','nj','07103','2018643110', '01-Jan-1992');
于 2012-11-06T02:29:07.607 回答
1

BIRTH_YR作为一个DATE字段应该以'yyyy-MM-dd'格式给出,'1992-01-01'。

于 2012-11-06T02:24:36.077 回答