在oracle中,减运算符和不存在会导致相同的结果

时间:2016-02-12 07:22:27

标签: database oracle11g not-exists

任何人都可以帮助确认在oracle减运算符中并且不存在返回相同的结果集吗?

此致 Mayuran

1 个答案:

答案 0 :(得分:1)

以下证明减号和不存在的查询不会返回相同的结果:

减号查询

with t1 as (select 1 id, 'a' val from dual union all
            select 1 id, 'a' val from dual union all
            select 2 id, 'b' val from dual),
     t2 as (select 2 id, 'b' val from dual union all
            select 3 id, 'c' val from dual)
select id, val
from   t1
minus
select id, val
from   t2;

减去结果

        ID VAL
---------- ---
         1 a  

不存在查询

with t1 as (select 1 id, 'a' val from dual union all
            select 1 id, 'a' val from dual union all
            select 2 id, 'b' val from dual),
     t2 as (select 2 id, 'b' val from dual union all
            select 3 id, 'c' val from dual)
select id, val
from   t1
where  not exists (select null
                   from   t2
                   where  t1.id = t2.id
                   and    t1.val = t2.val);

不存在结果

        ID VAL
---------- ---
         1 a  
         1 a