假如有一张表tab里有a和b字段,我要实现如下查询,假如a字段为null,就b=某个值,假如a不为null,就a=某个值,按这种查询,条件该怎么写呢?

解决方案 »

  1.   

    select nvl(a,b) as col from t或用decode
      

  2.   

    1楼理解错了,我的意思是where后面的条件是a字段为null,就b=某个值,假如a不为null,就a=某个值.条件该怎么写呢
      

  3.   

    where (a is null and ...) or (a is not null and ..)
      

  4.   

    select * as col from t where nvl(a,b)=某个值
      

  5.   

    select * ,case a is null then b=某个值 else a=某个值 from tablename 
      

  6.   

    WHERE DECODE(A,NULL,B,A) = DECODE(A,NULL,B_VALUE,A_VALUE)
      

  7.   

    case....when 应该可以满足楼主的要求
      

  8.   

    1、select decode(a,null,'值1','值2') from t;2、select case when a is null then '值1' else '值2' end from t;
    楼主想要的应该是根据a为空时显示什么,不为空时显示什么,跟b没有什么关系,只是查询又不是更新