没有秒的 oracle 时间戳

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

oracle timestamp without seconds

sqloracleoracle10g

提问by RNJ

I have a timestamp(6) column in a table in my database. I would like to do a comparison on it but without considering the seconds part. I know that I can trunc(timestamp) to remove the time and leave the date part. Is there a way I can set the seconds to 0?

我的数据库表中有一个时间戳(6)列。我想对其进行比较,但不考虑秒部分。我知道我可以 trunc(timestamp) 删除时间并保留日期部分。有没有办法可以将秒数设置为 0?

I want to do this:

我想做这个:

CASE WHEN ARR NOT BETWEEN FROM AND TO THEN 1
     ELSE 0 END "mismatch"

..but get mismatches when the ARRhas a seconds part greater than FROMand TO. I dont care about seconds and only want to consider minutes.

..但是当 的ARR秒部分大于FROM和时会出现不匹配TO。我不在乎秒,只想考虑分钟。

Any advice greatly appreciated.

非常感谢任何建议。

Thanks

谢谢

回答by Alex Poole

The trunc()functionallows you so decide how much of the precision to discard via the optional fmtparameter; the default is to remove all time components, i.e. the equivalent of trunc(x, 'DD'). If you want to only lose the seconds you can use MI:

trunc()函数允许您通过可选fmt参数决定丢弃多少精度;默认是删除所有时间分量,即相当于trunc(x, 'DD'). 如果你只想失去你可以使用的秒数MI

select systimestamp, trunc(systimestamp, 'MI') from dual;

SYSTIMESTAMP                        TRUNC(SYSTIMESTAMP,'MI')
----------------------------------- ------------------------
06-JAN-14 13.11.33.046920000 +00:00 2014-01-06 13:11:00      

Note that the value returned from truncis now a DATE, not a TIMESTAMP. If that is an issue - which is may well not be - you can cast it back:

请注意,从trunc现在返回的值是 a DATE,而不是 a TIMESTAMP。如果这是一个问题 - 这很可能不是 - 您可以将其退回:

select systimestamp, cast (trunc(systimestamp, 'MI') as timestamp) from dual;

SYSTIMESTAMP                        CAST(TRUNC(SYSTIMESTAMP,'MI')ASTIMESTAMP)
----------------------------------- -----------------------------------------
06-JAN-14 13.14.43.270506000 +00:00 2014-01-06 13:14:00.000