查询语句: select t.* from V_Storage_Bill t where t.storage_bill_billcode not in (
   select a.fee_optcode from Settlement_Fee a );
  查不到数据,但是将子查询换成如下
  select t.* from V_Storage_Bill t where t.storage_bill_billcode not in (‘ttttt’);
  可以查到数据,纠结。。
难道视图中不能有子查询吗。

解决方案 »

  1.   

    将查询语句改成select t.* from V_Storage_Bill t where t.storage_bill_billcode in (
      select a.fee_optcode from Settlement_Fee a ); 也查得到数据44条,视图中存在162条,不知道为什么
      

  2.   


    select t.* 
    from V_Storage_Bill t left join 
    Settlement_Fee a on t.storage_bill_billcode=a.fee_optcode
    where a.fee_optcode is null
      

  3.   

    为了好解释,举个例子:
    SELECT 1 FROM dual WHERE '1' NOT IN (SELECT NULL FROM dual)
    就没有查询结果,因为null特殊,不能和任何值匹配,解决方案,第2种方法最好
    1:SELECT 1 FROM dual WHERE '1' NOT IN (SELECT nvl(NULL, ' ') FROM dual)2:NOT EXISTS
    select t.* from V_Storage_Bill t where NOT EXISTS(
      select 0 from Settlement_Fee a WHERE t.storage_bill_billcode = a.fee_optcode );