2个表中,有一个字段都是为空  table1.col1=table2.col2 这2个字段都为空,难道不行吗? 请教高手!!!!!

解决方案 »

  1.   

    null 参加的运算结果仍是 nullNULL=NULL -> NULL
    NULL>3  ->NULL
    你可以加上or ( table1.col1 is null and table2.col2 is null)
      

  2.   

      我不能这样写,应该有的行很有可能不会是null  但有的列又是null
     
    and a.class1=b.class1 and a.class2=b.class2 and a.class3=b.class3 and a.class4=b.class4 and a.class5=b.class5 and a.class6=b.class6 这是我所带的条件。每行都是不一样的,很可能第5行某个字段是空,但是第6行又不是空了,所以不能直接加is null的条件。这样不就判断不到不为null的么?
      

  3.   

    利用nvl处理一下:
    nvl(table1.col1,' ')=nvl(table2.col2,' ') 
      

  4.   

    and nvl(a.class1,1)=nvl(b.class1,1) and nvl(a.class2,1)=nvl(b.class2,1) and ....
      

  5.   

    同意楼上做法!
      在Oracle中不能拿null和null直接比较!
     因为你既不能说它们相等,也不能说它们不相等!
      不知道你能明白吗?
      

  6.   

    null不等于任何值,当然不会等于null,你可以用nvl来转化一下!
      

  7.   


    不行,空是不能用=和其他逻辑做判断的, 返回都是falsenull的字段只能用is null 或者 is not null
      

  8.   

    NULL和NULL的比较唯一只能在decode中起作用,在case when或者其他运算都是false.
    SQL> select decode(null,null,2,3) from dual;DECODE(NULL,NULL,2,3)
    ---------------------
                        2SQL> select case null when null then 1 else 2 end from dual;CASENULLWHENNULLTHEN1ELSE2END
    -----------------------------
                                2