SQL> select*from aa;
   ID NAME
---------------  ------------------------------------
       11 aa
       22 bb
       33
SQL> select *from bb;
   ID NAME
--------------  ------------------------------------
   33 cc
       11 aa 
       22 bb
SQL>select*from bb where name not in (select name from aa);
No rows selected
ID是number类型,name是varchar2(10)类型,为什么查询没有任何返回,请列出可能的原因?

解决方案 »

  1.   

    因为是 not in null了,所以,没有显示。
    null值是不能用in来操作的。
    此外,这种情况,用左连接效率更高select bb.* from aa,bb
    where bb.name = aa.name(+)
    and aa.name is null
      

  2.   

    HAVE A TRY:HAVA A TRY:witH a as
    (select 1 id,'a' name from dual
    union all
    select 2 id,'b' name from dual
    union all
    select 3 id,null name from dual
    ),b as(select 1 id,'a' name from dual
    union all
    select 2 id,'b' name from dual)
    select * from a where not exists (select 1 from b where a.name = b.name);