oracle中有没有类似于sqlserver中的case 内置函数
问题:
    A、 表中有 id,a1,a2,b1,b2,c1,c2,k   字段
    依据条件if b1 - a1 <-k then c1= b1 - a1 else c1=a1 -b1 end if;
           if b2 - a2  <-k then c2=b2- a2  else c2=a2 -b2 end if;
更新表中的 c1,c2

解决方案 »

  1.   

    <-k还是<=k
    如果是<=k
    update table set
      c1 = decode(sign(b1-a1-k), 1, a1-b1, b1-a1),
      c2 = decode(sign(b2-a2-k), 1, a2-b2, b2-a2)
      

  2.   

    in oracle9i:
    you can use "case" just like in ms sql
      

  3.   

    用decode可以,但不能做大小的比较,只能用等的关系。不过可以通过运算得到等的关系,象things(平)写的那样。如果是9i,则可以使用:case,灵活些。