减号运算符和不存在是否导致 oracle 中的结果相同

Does minus operator and not exist result in same result in oracle

任何人都可以帮助确认在 oracle minus operator 和 not exists 中返回相同的结果集吗?

此致, 马玉兰

这里证明 minus 和 not exist 查询不 return 相同的结果:

减号查询

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