如何在oracle中使用增量值为30分钟来递增datetime值? [英] how to increment the datetime value with the increment value as 30 minutes in oracle?

查看:263
本文介绍了如何在oracle中使用增量值为30分钟来递增datetime值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在oracle中以30分钟为增量值增加datetime值? 在mssql中,我使用以下查询解决了我的问题,我需要在oracle中使用等效查询

how to increment the datetime value with the increment value as 30 minutes in oracle? In mssql i used the following query for solve my problem, i need the equivalent query in oracle

 with mycte as(
       select cast('2012-01-01 00:00:00' as datetime) DateValue union all 
       select dateadd(minute,30,DateValue) from mycte where  dateadd(minute,30,DateValue) <= '2012-01-01 23:59:00')
 select DateValue from  mycte option (maxrecursion 32767);

上述查询的结果如下:

DateValue
2012-01-01 00:00:00.000
2012-01-01 00:30:00.000
2012-01-01 01:00:00.000
2012-01-01 01:30:00.000
2012-01-01 02:00:00.000
2012-01-01 02:30:00.000
2012-01-01 03:00:00.000
2012-01-01 03:30:00.000
2012-01-01 04:00:00.000
2012-01-01 04:30:00.000
2012-01-01 05:00:00.000
2012-01-01 05:30:00.000
2012-01-01 06:00:00.000
2012-01-01 06:30:00.000
2012-01-01 07:00:00.000
2012-01-01 07:30:00.000
2012-01-01 08:00:00.000
2012-01-01 08:30:00.000
2012-01-01 09:00:00.000
2012-01-01 09:30:00.000
2012-01-01 10:00:00.000
2012-01-01 10:30:00.000
2012-01-01 11:00:00.000
2012-01-01 11:30:00.000
2012-01-01 12:00:00.000
2012-01-01 12:30:00.000
2012-01-01 13:00:00.000
2012-01-01 13:30:00.000
2012-01-01 14:00:00.000
2012-01-01 14:30:00.000
2012-01-01 15:00:00.000
2012-01-01 15:30:00.000
2012-01-01 16:00:00.000
2012-01-01 16:30:00.000
2012-01-01 17:00:00.000
2012-01-01 17:30:00.000
2012-01-01 18:00:00.000
2012-01-01 18:30:00.000
2012-01-01 19:00:00.000
2012-01-01 19:30:00.000
2012-01-01 20:00:00.000
2012-01-01 20:30:00.000
2012-01-01 21:00:00.000
2012-01-01 21:30:00.000
2012-01-01 22:00:00.000
2012-01-01 22:30:00.000
2012-01-01 23:00:00.000
2012-01-01 23:30:00.000

我需要在oracle中进行等效查询,

I need the equivalent query in oracle,,

推荐答案

另一种方法可能是

select to_date('2012-01-01', 'yyyy-mm-dd') + (level-1)/48 as datetime 
  from dual
connect by level <= 48

这篇关于如何在oracle中使用增量值为30分钟来递增datetime值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆