简体   繁体   English

Oracle数据库的TO_TIMESTAMP函数

[英]TO_TIMESTAMP function for Oracle Database

TO_TIMESTAMP('2018-09-07 18:43:56.302000', 'YYYY-MM-DD hh24:mi:ss.ff')

TO_TIMESTAMP('2018-09-07 18:43:56.302000', 'YYYY-MM-DD HH24:MI:SS.FF')

Hi, is there any difference if I use hh24 instead of HH24 in TO_TIMESTAMP ? 嗨,如果我在TO_TIMESTAMP使用hh24而不是HH24 ,有什么区别吗? same thing also for mi instead of MI , or ssv instead of SS`? 同样的事情也适用于mi而不是MI ,或ssv instead of SS`?

When you convert FROM string TO timestamp, the case is irrelevant. 将FROM字符串转换为时间戳时,情况无关紧要。 Oracle will even accept Mon for month, when the input is written as AUG or aug . 当输入被写为AUGaug时,Oracle甚至会接受Mon的月份。

The case used in the format model only matters when you convert FROM timestamp TO string, and even then, only for the components whose output is in letters, not digits. 格式模型中使用的情况仅在将FROM时间戳转换为字符串时才有意义,即便如此,仅适用于输出为字母而非数字的组件。 So, even for TO_CHAR , it doesn't matter if you write YYYY or yyyy or YyyY for the year, they will all be accepted and give the same result. 因此,即使对于TO_CHAR ,如果你今年写YYYYyyyyYyyY并不重要,它们都将被接受并给出相同的结果。 The only difference is that MON will return AUG , Mon will return Aug and mon will return aug . 唯一的区别是MON将返回AUGMon将返回Augmon将返回aug And similar for elements like Dy and DAY , etc. 类似于DyDAY等元素。

So, the answer to your question is "it doesn't matter" for TWO independent reasons: capitalization doesn't matter when you convert FROM string TO timestamp, and it doesn't matter for numeric (as opposed to "text") elements anyway. 所以,你的问题的答案是“无关紧要”有两个独立的原因:当你将FROM字符串转换为时间戳时,大写并不重要,而且对于数字(而不是“text”)元素并不重要无论如何。 All versions are valid and produce the same result. 所有版本都有效并产生相同的结果。

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

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