简体   繁体   English

EXISTS子查询Oracle 11.2与Oracle 12.1

[英]EXISTS subquery Oracle 11.2 versus Oracle 12.1

I'm struggling with this weird thing (don't bother about the signification of this exemple, it's just a sample to highlight the issue). 我正在为这个怪异的事物而苦苦挣扎(不要理会这个例子的含义,它只是一个突出问题的示例)。 The following code runs well on Oracle 12.1.0.2.0, but fails on 11.2.0.3.0. 以下代码在Oracle 12.1.0.2.0上运行良好,但在11.2.0.3.0上失败。

create table test_0 as
select 1 as un, 2 as deux
from dual
;

create table test_1 as
select 1 as un, 3 as trois
from dual
;             

select deux
from test_0 t0
where exists (select 1 from (select trois from test_1  t1 where t1.un = 
t0.un))
;

Does anyone have an explanation for this? 有人对此有解释吗?

You are getting this with Oracle before Oracle 12.1 在Oracle 12.1之前使用Oracle即可获得此功能

ORA-00904: "T0"."UN": invalid identifier

Because in prior versions, Oracle was not able to determine the context where t0 was defined. 因为在以前的版本中,Oracle无法确定定义t0的上下文。 So this appears to be an improvement of the version. 因此,这似乎是该版本的改进。

"t0.un" (at the very end of your query) is too deeply nested (2 levels, that is). “ t0.un”(在查询的最后)嵌套太深(即2个级别)。 It "works" if you move it level up (disregard the fact that it is probably meaningless) such as 如果您将其向上移动(不管它可能毫无意义的事实),它将“起作用”,例如

SELECT deux
  FROM test_0 t0
 WHERE EXISTS
          (SELECT trois
                     FROM test_1 t1
                    WHERE t1.un = t0.un); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM