RToracle数据库中已知 :
select 
    t.a,
    t.b
 from 
   table1 t , table2 t2
where 
   t.c=t2.c and
   t.d =
   case &param='01' then '1'   --想在此处多加一条语句。像这样: case &param ='01' then t.d='1' and t.e='1' .但这样写 编译不通过。尝试用if 语句 编译也通不过。现在需要这样的逻辑判断,请问各位大侠该如何实现啊
   case &param ='02' then '2'
 end case 
  and t.f = 0;问题描述完毕。
简单来说就是想做这样的判断,当参数为01的时候,想让t.d='1' 并且 and t.e='1' 。
当参数为02的时候。想让t.d='2'并且 and t.e='2'.

解决方案 »

  1.   


    --楼主是不是想要这个样子
    select  
      t.a,
      t.b
     from  
      table1 t , table2 t2
    where  
      t.c=t2.c and
      t.d = decode(&param,'01','1','02','2')
    and t.e=decode(&param,'01','1','02','2')
      

  2.   


    是的。要的就是这个。这样可以解决问题,但相当于写了两遍case when 呢  
      

  3.   

    decode的效率还是很高的,我觉得这个不需要担心吧,再来说其实也可以写case when,只不过case完了后还是和decode一样,不能把最后的那个条件一块并入前面的条件
      

  4.   

    我还以为oracle会提供什么函数来实现我要的功能呢。这种语句用PL/SQL写简单多了
    不过还是谢谢你了