1

如何更改 Oracle 中时间戳的粒度?

例如:

28.10.2013 15:15:15

28.10.2013 15:00:00
4

1 回答 1

3

您将使用trunc命令

样本数据:

with dates as ( -- generating sample data
select to_date('10/28/2013 09:08:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('10/28/2013 09:18:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('10/28/2013 09:38:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('10/28/2013 09:48:19', 'mm/dd/yyyy hh:mi:ss') from dual)

要运行的查询:

select dt,
    trunc(dt,'hh') as new_dt
from dates

结果是

DT                   new_dt
-------------------- -------------------
2013-10-28 09:08:19  2013-10-28 09:00:00
2013-10-28 09:18:19  2013-10-28 09:00:00
2013-10-28 09:38:19  2013-10-28 09:00:00
2013-10-28 09:48:19  2013-10-28 09:00:00
于 2013-10-28T14:20:54.123 回答