select ( case when a is null and b is not null then b when a is not null and b is null then a when a is null and b is null then null else a - b end ) from tb

解决方案 »

  1.   

    select decode(a,null,decode(b,null,null,b),decode(b,null,a,a-b)) from tb;
      

  2.   

    SELECT decode(A,null,
                  decode(B,null,null,B),     <- 这是 A=null 的判断
                  decode(B,null,A,A-B)       <- 这是 A!=null 的判断
                 )
    FROM tab_name
      

  3.   

    晕倒~ 
    写晚了 :(原来  zmgowin(隐者(龙祖宗))  也在写~  并且比我快一步~  pfpf. :)
      

  4.   

    select decode(a,null,decode(b,null,null,b),decode(b,null,a,a-b)) from tb;
      

  5.   

    select A || decode(a,null,null,decode(b,null,null,'-')) || B from tb;或者select A || (case when a is not null and b is not null then '-' end) || B from tb;
      

  6.   

    觉得这种情况用case写更清楚一些
      

  7.   

    select nvl2(A,nvl2(B,A-B,A),B) from tb;