且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:ORA-01790:表达式必须具有与相应表达式相同的数据类型

更新时间:2021-12-23 21:58:49

由于您使用的是基本发行版,因此看起来像11840579.您可以通过强制转换值来解决它-不必这样做,但这是您的错误:

Since you're on the base release this looks like but 11840579. You may be able to work around it by casting the value - it shouldn't be necessary, but that's bugs for you:

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;

在转换中包括多余的元素是没有意义的;我个人还是喜欢日期文字:

Including extra elements in the conversion is a bit pointless; personally I prefer date literals anyway:

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)这两个值是略有不同的类型,具有不同的内部表示形式,这似乎是导致问题的原因:

The two values, date '2015-01-01' and cast(date '2015-05-01' as date) are slightly different types, with different internal representations, which seems to be causing the problem:

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   

但是,该错误还有另外一部分,那就是它可以返回错误的结果.如果您无法修补以避免出现此问题,则可以使用较旧的分层查询方法:

However there's a second part to the bug which is that it can return the wrong results. If you can't patch up to avoid the problem, you could use the older hierarchical-query approach:

select level as id, date '2015-05-01' + level - 1 as dateN
from dual
connect by level < 10;