最近在写一个视图,在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'的,否则相反,不知各位有没有明白我的意思。
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'的,否则相反,不知各位有没有明白我的意思。
里面用过.
用decode来代替case试试
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