运行以下内容我收到错误Error: ORA-01790: expression must have same datatype as corresponding expression
with x (id, dateN) as
(
select 1, to_date('2015-05-01 00:00:00','YYYY-MM-DD HH24:MI:SS') from dual
union all
select id+1, dateN+1 from x where id < 10
)
select * from x
我尝试过像to_char这样的不同演员阵容,如时间戳,+间隔&#39; 1&#39;一天等等,但这个错误不断出现。在Mssql上,通过函数dateadd('dd', 1, dateN)
非常容易,但是如何实现这一目标并不是很明显。
Oracle Database 11g企业版11.2.0.1.0版 - 64位生产
答案 0 :(得分:2)
因为你在基础版本上看起来像11840579.你可以通过转换值来解决它 - 它不应该是必要的,但这对你来说是错误的:
with x (id, dateN) as
(
select 1, cast(to_date('2015-05-01 00:00:00','YYYY-MM-DD HH24:MI:SS') as date) from dual
union all
select id+1, dateN+1 from x where id < 10
)
select * from x;
在转换中包含额外的元素是没有意义的;我个人更喜欢日期文字:
with x (id, dateN) as
(
select 1, cast(date '2015-05-01' as date) from dual
union all
select id+1, dateN+1 from x where id < 10
)
select * from x;
两个值date '2015-01-01'
和cast(date '2015-05-01' as date)
是略有不同的类型,具有不同的内部表示,这似乎导致了问题:
select dump(date '2015-05-01', 16) as d1, dump(cast(date '2015-05-01' as date), 16) as d2
from dual;
D1 D2
-------------------------------- --------------------------------
Typ=13 Len=8: df,7,5,1,0,0,0,0 Typ=12 Len=7: 78,73,5,1,1,1,1
然而,错误的第二部分是它可以返回错误的结果。如果您无法修补以避免此问题,则可以使用旧的分层查询方法:
select level as id, date '2015-05-01' + level - 1 as dateN
from dual
connect by level < 10;