最近在写一个视图,在where条件中需要用到条件判断。
where nt_bill.co_code = (case when nt_bill.co_code not in bm_outstore.co_code  then  bm_outstore.destin_code else bm_outstore.co_code end)
and as_org.org_code = (case when bm_outstore.destin_org_code is null  then  '0001'  else bm_outstore.destin_org_code end)我截出了两句,但是要把这两句并成一句写。假设上面判断后执行了 nt_bill.co_code=bm_outstore.destin_code ,下面肯定是执行as_org.org_code='0001'的,否则相反,不知各位有没有明白我的意思。

解决方案 »

  1.   

    从来没有见过case能够用在where里面的。
      

  2.   

    CASE WHEN写在SELECT里。用CASE WHEN的目的不就是替代WHERE 吗
      

  3.   

    只见过case 用在select ....from  和order by
    里面用过.
      

  4.   

    select * from tt_01 where xh=decode(xh,'aa','1',xh);
    用decode来代替case试试
      

  5.   

    更正一下我的错误:
    SQL> select *from t2;COL1       COL2                                                                 
    ---------- ----------                                                           
    111        XXXX                                                                 
    111        XXX                                                                  
    222        DDD                                                                  
    444        EEE                                                                  SQL> select * from t2 where col1=decode(col2,'XXX','111','DDD','222');COL1       COL2                                                                 
    ---------- ----------                                                           
    111        XXX                                                                  
    222        DDD                                                                  SQL> SPOOL OFF