读书人

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

发布时间: 2012-05-27 05:42:30 作者: rapoo

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

读书人网 >oracle

热点推荐