2012-07-04 27 views
0

如何在oracle中將增量值增加爲30分鐘的日期時間值? 在MSSQL我用下面的查詢解決我的問題,我需要Oracle中的等效的查詢如何在oracle中將增量值增加爲30分鐘的日期時間值?

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中等效的查詢,,

回答

1

另一種方式可能是

select to_date('2012-01-01', 'yyyy-mm-dd') + (level-1)/48 as datetime 
    from dual 
connect by level <= 48 
2
with mycte as (
    select timestamp '2012-01-01 00:00:00' + interval '30' minute * level as DateValue 
    from dual 
    connect by level < 48 
) 
select * 
from mycte;