1. 程式人生 > >Oracle decode 用法

Oracle decode 用法

DECODE用法:

           DECODE(value,if1,then1,if2,then2,if3,then3,...,else)

 含義為:              if 條件=值1 then            return(value 1)

             else if 條件=值2 then             return(value 2)     ......

               else if 條件=值n then              return(value 3)               else              return(default) END IF

ps:

         A,B在資料庫為float型別

        decode(A,B,0,1) :當A=B,返回0,否則返回1

select httz.HETONG_BIAOHAO,HETONG_ZONGJINE,heji,decode(HETONG_ZONGJINE,heji,0,1)
from t_htybz_httz httz left join (
    select HETONG_BIANHAO,sum(JIESUAN_HEJIA) heji
    from T_HTYBZ_WLJSDB 
    group by HETONG_BIANHAO
) sdb
on httz.HETONG_BIAOHAO=sdb.HETONG_BIANHAO