oracle ORA-01855:需要 AM/AM 或 PM/PM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9664231/
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-10 04:02:26  来源:igfitidea点击:

ORA-01855: AM/A.M. or PM/P.M. required

oracledateoracle10gnls-lang

提问by RMN

I get the error: ORA-01855: AM/A.M. or PM/P.M. required

我收到错误: ORA-01855: AM/A.M. or PM/P.M. required

when I try to execute following query.

当我尝试执行以下查询时。

  INSERT INTO TBL(ID,START_DATE) 
    values (123, TO_DATE ('3/13/2012 9:22:00 AM', 'MM/DD/YYYY HH:MI AM'))

Where my START_DATEcolumn is of type "Date".

我的START_DATE专栏的类型是“日期”。

I have executed following query and it gave no errors, still not success yet in above issue:

我已经执行了以下查询并且它没有给出任何错误,在上述问题中仍然没有成功:

ALTER SESSION SET NLS_DATE_FORMAT = "MM/DD/YYYY HH:MI AM";

回答by Justin Cave

Your format mask must match the format of the string you are converting. So you would either want to add SSto the format mask or remove the seconds from the string

您的格式掩码必须与您要转换的字符串的格式相匹配。所以你要么想添加SS到格式掩码或从字符串中删除秒

INSERT INTO TBL(ID,START_DATE) 
  values (123, TO_DATE ('3/13/2012 9:22:00 AM', 'MM/DD/YYYY HH:MI:SS AM'))

or

或者

INSERT INTO TBL(ID,START_DATE) 
  values (123, TO_DATE ('3/13/2012 9:22 AM', 'MM/DD/YYYY HH:MI:SS AM'))

If you want to accept a string that contains seconds but you don't want to store the seconds in the database (in which case Oracle will always store 0 for the seconds), you can use the TRUNCfunction

如果您想接受一个包含秒的字符串,但又不想将秒存储在数据库中(在这种情况下,Oracle 将始终为秒存储 0),您可以使用该TRUNC函数

INSERT INTO TBL(ID,START_DATE) 
  values (123, TRUNC( TO_DATE ('3/13/2012 9:22:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 'MI') )

回答by Md Faramawy

I got the same error when running the form builder, It was fixed by changing the Filed DataType from TIME to CHAR.

我在运行表单构建器时遇到了同样的错误,它是通过将 Filed DataType 从 TIME 更改为 CHAR 来修复的。