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
Oracle - literal does not match format string error
提问by AkshaiShah
Possible Duplicate:
Simple Oracle query: literal does not match format string
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 DATE
format.
第一个字段是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 INSERT
using 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);
回答by Gaurav Soni
Try this SQL:
试试这个 SQL:
INSERT INTO CatalogueEntry
VALUES(to_date('2001-12-10','yyyy-mm-dd'), 2, 14.99, 1, 0);