我试图使用递归视图生成一些数据,但它的工作方式与我预期的不同。每次从开始日期扣除一天:
with x (id, start_date, tmp) as
(
select id, start_date, 1 from my_table
union all
select id+1, start_date + tmp, tmp+1 from x where id <=5
)
select * from x
结果:
2015-03-01 00:00:00.0
2015-02-28 00:00:00.0
2015-02-27 00:00:00.0
2015-02-26 00:00:00.0
2015-02-25 00:00:00.0
然后我尝试用一个更简单的例子来测试它,并得到了错误:
with x (id, date_test) as
(
select 1, trunc(to_date('01/01/2015','dd/mm/yyyy')) from dual
union all
select id+1, date_test from x where id <=5
)
select * from x
错误:
错误:ORA-01790:表达式的数据类型必须与对应的相同
表达式SQLState:42000错误代码:1790位置:114
查询
select 1, trunc(to_date('01/03/2015','dd/mm/yyyy'))
from dual
有效:
1 2015-01-01 00:00:00.0
事实上,我曾使用connectby进行过工作,但我想知道为什么会发生这种情况。我曾经使用Sql Server,在那里这种方法是可行的,但在oracle中,我仍然找不到发生这种情况的原因。