Reputation: 149
I want to write a query in oracle sql, which returns every minute of the current day in one column. But i've got no idea, how to start :-(
min
27.03.2014 00:00
27.03.2014 00:01
27.03.2014 00:02
...
27.03.2014 23:59
Thanks
Upvotes: 0
Views: 4190
Reputation: 2602
You can use numtodsinterval
function and is simple too:
SELECT to_char(TRUNC(sysdate)+
numtodsinterval (level-1,'minute'),'dd.mm.yyyy hh24:mi') min
FROM dual
CONNECT BY LEVEL <= (24*60);
Upvotes: 2
Reputation: 1062
SELECT date + minute FROM
(
SELECT TO_DATE('yyyy.mm.dd', '2014.03.27') date FROM DUAL
CROSS JOIN
(
SELECT 0 minute FROM DUAL
UNION ALL
SELECT rownum r
FROM DUAL
CONNECT BY rownum <= 1439
) T
) TT
Upvotes: 0
Reputation: 146199
We can use arithmetic to manipulate dates, and the simple CONNECT BY trick to generate a stream of rows.
alter session set nls_date_format='dd-mon-yyyy hh24:mi'
/
with cte as ( select trunc(sysdate) as start_date from dual )
select start_date + ((level-1)/(24*60)) as date_w_mins
from cte
connect by level <= (24*60)
/
Upvotes: 3