首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

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

2012-05-27 
oracle case when 多条件控制语句RToracle数据库中已知 :selectt.a,t.bfromtable1 t , table2 t2wheret.c

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') 

热点排行