遇到一业务,用到一个sql不会写了,抽象出来是这样:
字段1引用字段2
比方这样:selec 1 a ,case when a=1 then 'b1' else 'b2' end from dual;
就是说,要查两个字段,如果a=1的话,b就是b1,否则就是b2如何解决,求教!

解决方案 »

  1.   

    看样子是存储过程里用的.
    直接
    select 变量,case 变量=1 then b1 else b2 end from table
      

  2.   

    你是要从一个表中查一个字段,然后根据字段是不是等于1让他来显示不同的值select decode(a,1,'b1','b2') from table;
      

  3.   

    select a, decode(a,1,'b1','b2') from (select 1 a from dual);
      

  4.   

    你的两个行,我的要求有三个
    a=1的话是 b1
    a=2的话是 b2
    a=3的话是 b3
    还能用这个函数吗?
      

  5.   


    select decode(a,1,'b1',2,'b2',3,'b3') from table;
      

  6.   

    decode(a,1,b1,2,b2,3,b3....n,bn,bn+1),中间的可以重复.
    case类似.
      

  7.   

    你的b1 b2是字段的话 去掉引号便可 ;不是字段的话是值 就你的这样可以
    selec 1 a ,decode(a,1,'b1','b2') b from dual;
      

  8.   

    这个随你
    select 1 a,decode(a,1,'b1',2,'b2',3,'b3',....n,'bn') b from table;
      

  9.   


    select a1, case when a1=1 then b1 else b2 end b from table_name
      

  10.   


    select a1, case when a1=1 then 'b1' else 'b2' end b from table_name