Oracle 时间戳:提取整小时

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

Oracle Timestamp: extract full hour

sqloracletimestamp

提问by reto

I need to extract the 'full' hour of a timestamp. Like for 2010.03.04 13:13 I want 2010.03.04 13:00 (as a timestamp again).

我需要提取时间戳的“完整”小时。就像 2010.03.04 13:13 我想要 2010.03.04 13:00 (再次作为时间戳)。

My current approach is:

我目前的做法是:

TO_TIMESTAMP(TO_CHAR(m.begin, 'yyyy.mm.dd hh24'), 'yyyy.mm.dd hh24')

Is this really the way to go? Who good/bad does it perform (I plan to do a GROUP BY on it).

这真的是要走的路吗?它表现的好/坏(我计划对其进行 GROUP BY)。

Thanks for your input!

感谢您的输入!

Cheers, Reto

干杯,雷托

回答by Quassnoi

SELECT  TRUNC(m.begin, 'HH24')
FROM    mytable m

回答by álvaro González

You can use the TRUNC() function:

您可以使用 TRUNC() 函数:

http://www.psoug.org/reference/date_func.html

http://www.psoug.org/reference/date_func.html