Using Oracle 11g release 2, the following query gives an ORA-01790: expression must have same datatype as corresponding expression:
with intervals(time_interval) AS
(select trunc(systimestamp)
from dual
union all
select (time_interval + numtodsinterval(10, 'Minute'))
from intervals
where time_interval < systimestamp)
select time_interval from intervals;
The error suggests that the datatype of both subqueries of the UNION ALL are returning different datatypes.
Even if I cast to TIMESTAMP in each of the subqueries, then I get the same error.
What am I missing?
EDIT: I'm not looking for a CONNECT BY replacement.
I have no idea about the type mismatch, but here is an alternative method to accomplish what I think you want (which works in 10gr2):
In my opinion, "Recursive Subquery Factoring" is broken in 11g R2 for queries with date or timestamp column.
use a cast to convert the datatype:
Casting a date into a date is helping, but where are the other results?
It gets even better...
Try it with another start date:
Counting backwards? Why?
Update 14-Jan-2014: As a workaround, use the CTE starting with the end date and building the recursive CTE backwards, like this:
Results:
Test conducted with:
Odd - works if you pass around
varchar
s and convert (not cast):