简体   繁体   English

使用AM时出现“需要AM / AM或需要PM / PM”错误

[英]“AM/A.M. or PM/P.M. required” error though AM is used

I have table_name on oracle 12c which has column_name1 with data type "TIMESTAMP(6) WITH TIME ZONE". 我在oracle 12c上具有table_name,它的column_name1的数据类型为“ TIMESTAMP(6)WITH TIME ZONE”。 I am using SQL Developer. 我正在使用SQL Developer。

When I select anything from this column_name1 using SQL Developer, I see the date like: 19-SEP-17 03.19.55.000000000 PM +00:00 which is in UTC. 当我使用SQL Developer从column_name1中选择任何内容时,会看到类似UTC的日期: 19-SEP-17 03.19.55.000000000 PM +00:00

If I use same format in my SQL and give it as string in where clause it works fine. 如果我在SQL中使用相同的格式,并在where子句中将其作为字符串提供,则效果很好。 Example: 例:

select column_name1 from table_name where column_name1 = '19-SEP-17 03.19.55.000000000 PM +00:00';

But I know it is recommended to convert string to date in situations like this. 但是我知道在这种情况下建议将字符串转换为日期。 So when I am trying to do this using TO_TIMESTAMP, I am failing to find the correct format to add in the SQL. 因此,当我尝试使用TO_TIMESTAMP执行此操作时,我找不到要在SQL中添加的正确格式。

What I have tried is: 我试过的是:

select column_name1 from table_name where column_name1 = TO_TIMESTAMP('19-SEP-17 03.19.55.000000000 PM +00:00', 'DD-MON-YYYY HH:MI:SS.FF A.M. TZH:TZM');

And even though AM/PM is already there, I still get error as: AM/AM or PM/PM required 即使AM / PM已经存在,我仍然会收到以下错误消息:需要AM/AM or PM/PM required

I have tried adding 'nls_date_language=american' as well but still get same error. 我也尝试添加'nls_date_language = american',但仍然收到相同的错误。

What am I missing here? 我在这里想念什么? How can I change the TO_TIMESTAMP format so I can convert this string to TIMESTAMP? 如何更改TO_TIMESTAMP格式,以便可以将此字符串转换为TIMESTAMP?

Are you, actually, using TO_TIMESTAMP_TZ - as you should, since the column is timestamp WITH TIME ZONE, and the input string and the format model are both for timestamp WITH TIME ZONE? 实际上,您实际上是否在使用TO_TIMESTAMP_TZ因为该列是带有WITH TIME ZONE的时间戳,并且输入字符串和格式模型都是带有WITH TIME ZONE的时间戳? (If you were using TO_TIMESTAMP like that you would get a different error, something like "date format not recognized" - since you can't have timezone format elements in the format model for a timestamp WITHOUT timezone). (如果您像这样使用TO_TIMESTAMP ,则会收到其他错误,例如“无法识别日期格式”,因为格式模型中的时区格式元素不能包含没有时区的时间戳)。

Assuming that is the case: The problem is caused by passing PM (without dots) in the input string, but having AM (with dots) in the format model. 假设是这种情况:问题是由在输入字符串中传递PM (不带点),但在格式模型中具有AM (带点)引起的。 Use the same format in both places - either with dots, or without them, but be consistent. 在两个地方都使用相同的格式-带点或不带点,但要保持一致。

In some places Oracle doesn't fuss over mismatched separators, but in this case it does. 在某些地方,Oracle不会为不匹配的分隔符大惊小怪,但在这种情况下,它确实做到了。 If you like you can hunt through the documentation to find out exactly which substitutions Oracle will attempt; 如果愿意,您可以翻阅文档以找出Oracle将会尝试哪种替代方案;以及 but that sounds like an academic exercise. 但这听起来像是一项学术练习。 Just be consistent between the input string and the format model and you won't have any problems. 只要在输入字符串和格式模型之间保持一致,就不会有任何问题。

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

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