SQL Oracle - 文字与格式字符串不匹配错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13518506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:16:53  来源:igfitidea点击:

Oracle - literal does not match format string error

sqldatabaseoracledate-formatora-01861

提问by AkshaiShah

Possible Duplicate:
Simple Oracle query: literal does not match format string

可能的重复:
简单的 Oracle 查询:文字与格式字符串不匹配

I am getting the following error:

我收到以下错误:

INSERT INTO CatalogueEntry VALUES('2001-12-10', 2, 14.99, 1, 0)

ERROR at line 1: ORA-01861: literal does not match format string `

The first field is a DATEformat.

第一个字段是DATE格式。

Any ideas?

有任何想法吗?

Thanks.

谢谢。

回答by Taryn

When you are inserting a string value to a date column, then you need to convert it to a date during the INSERTusing the to_date()function. When using this function you will provide the format of the string.

当您将字符串值插入日期列时,您需要在INSERT使用该to_date()函数期间将其转换为日期。使用此函数时,您将提供字符串的格式。

to_date()function format:

to_date()函数格式:

to_date( string1, [ format_mask ], [ nls_language ] )

So your query will be like this:

所以你的查询将是这样的:

insert into CatalogueEntry
values
(
  to_date('2001-12-10', 'yyyy-mm-dd'),
  2,
  14.99,
  1,
  0);

See SQL Fiddle with demo

请参阅带有演示的 SQL Fiddle

回答by Gaurav Soni

Try this SQL:

试试这个 SQL:

INSERT INTO CatalogueEntry 
              VALUES(to_date('2001-12-10','yyyy-mm-dd'), 2, 14.99, 1, 0);