简体   繁体   English

无法将日期插入SQL表

[英]Can't insert date into SQL table

I've created the following table: 我创建了下表:

CREATE TABLE match(
match_id NUMBER(4,0), 
match_date DATE, 
attendance NUMBER(6,0), 
stadium_name VARCHAR2(40), 
tournament_id NUMBER(3,0),
CONSTRAINT match_id_pk PRIMARY KEY(match_id),
CONSTRAINT match_stadium_name_fk FOREIGN KEY(stadium_name) 
           REFERENCES stadium(stadium_name));

I attempt to insert the following line: 我尝试插入以下行:

INSERT INTO match VALUES(1001, '20130515', 90000, 'American Airlines Arena', 001);

Everything I've found tells me the format is YYYYMMDD. 我发现的所有内容都告诉我格式为YYYYMMDD。 However I keep getting ORA-01861: literal does not match format string. 但是我一直在收到ORA-01861:文字与格式字符串不匹配。

After using ( DESCRIBE match ) it says the length is only 7. I thought it was supposed to be 10. 使用( DESCRIBE match )后说长度只有7。我以为应该是10。

Thanks in advance for any help. 在此先感谢您的帮助。

Well, the format YYYYMMDD is probably not the database date format (you should look for NLS_DATE_FORMAT to see what's the db date format). 好吧,格式YYYYMMDD可能不是数据库日期格式(您应该寻找NLS_DATE_FORMAT来查看什么是数据库日期格式)。

But there's a NLS_DATE_FORMAT at the system level and a (maybe other) NLS_DATE_FORMAT at the session level. 但是,有一个NLS_DATE_FORMAT在系统级和(也许其他) NLS_DATE_FORMAT会话级。

You can achieve what you want using TO_DATE and specifying the format : 您可以使用TO_DATE并指定格式来实现所需的功能:

INSERT INTO match VALUES(1001, TO_DATE('20130515', 'YYYYMMDD'), 90000, 'American Airlines Arena', 001);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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