从 oracle tmstmp 字段中删除毫秒

2021-12-30 00:00:00 sql oracle11g oracle

我在 Oracle 中有一个 TIMESTAMP(6) 字段,我需要从时间中删除毫秒部分.

I have a TIMESTAMP(6) field in Oracle and I need to remove the millisecond component from the time.

例如我有

10/20/2014 10:34:06.356000 AM

我想删除毫秒,以便我有

and I would like to remove the milliseconds so that I have

10/20/2014 10:34:06 AM

您知道这样做的最佳方法吗?

Do you know the best way to do this?

谢谢!

推荐答案

这个怎么样?

select cast(col as timestamp(0))

避免四舍五入的最简单方法是使用 trunc() 或减去半秒:

The easiest way to avoid rounding is to use trunc() or to subtract half a second:

select cast(col - 0.5/(24*60*60) as timestamp(0))

相关文章