运行以下代码我得到了错误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,比如时间戳,+间隔'1‘日等等,但是这个错误不断出现。在Mssql上,通过函数dateadd('dd', 1, dateN)非常容易,但在这里,如何实现这一点并不是很明显。
Oracle数据库11g企业版发布11.2.0.1.0 -64位产品
发布于 2016-06-24 14:31:58
因为您是在基本发布版上,这看起来像是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 但是,bug还有第二部分,即它可能返回错误的结果。如果您不能修补以避免这个问题,您可以使用旧的分层查询方法:
select level as id, date '2015-05-01' + level - 1 as dateN
from dual
connect by level < 10;https://stackoverflow.com/questions/38015049
复制相似问题