I have a query, which creates a column that contains every minute for the next 24 hours after a date.
(SELECT TO_DATE ('05/07/2012 15:00:00', 'DD/MM/YYYY HH24:MI:SS')
+ (ROWNUM / 1440)
AS foo
FROM ( SELECT (ROWNUM - 1)
FROM DUAL
CONNECT BY LEVEL <= 1336));
The first row of foo is 15:01. This seemed wrong to me.
So I ran the subquery on it’s own:
SELECT (ROWNUM - 1) FROM DUAL CONNECT BY LEVEL <= 1336;
Which returned 0,1,2,3,4, etc as expected.
So I ran the subquery again but divided by 1440, and the first value is still 0.
So I thought that perhaps adding a 0 to a timestamp causes some wierdness, so I ran
SELECT TO_DATE ('05/07/2012 15:00:00', 'DD/MM/YYYY HH24:MI:SS') + (0/1440) FROM DUAL;
And still got 05/06/2012 15:00:00
So why does combining this back up again cause the first value to be 15:01?
Cause ROWNUM in the outer query is 1 the first time, not zero.