当前位置: 代码迷 >> Oracle开发 >> oracle case when 多条件控制语句,该怎么处理
  详细解决方案

oracle case when 多条件控制语句,该怎么处理

热度:99   发布时间:2016-04-24 07:29:34.0
oracle case when 多条件控制语句
RT

oracle数据库中

已知 :
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'.



------解决方案--------------------
SQL code
--楼主是不是想要这个样子select    t.a,  t.b from    table1 t , table2 t2where    t.c=t2.c and  t.d = decode(&param,'01','1','02','2')and t.e=decode(&param,'01','1','02','2')
  相关解决方案