更改时间戳粒度

时间:2013-10-28 14:08:00

标签: oracle oracle11g

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

例如:

28.10.2013 15:15:15

28.10.2013 15:00:00

1 个答案:

答案 0 :(得分: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