sql语句 根据条件分支执行--执行sql语句中的一部分(oracle)

来源:互联网 发布:网络作家收入如何 编辑:程序博客网 时间:2024/06/03 04:01

预热  case when 用法:

 (一):select case when 1=1 then 1 end from dual;

结果:

 

(二):

表结构:

 select (case when xm='gao' then '姓高的销售额' when xm= 'zhu' then '姓朱的销售额' end ), sal from table3;

结果:

 

 

 

 

 

 ---------------------------------------------------------------------------------------预热结束-----------------------------------------------------------------------------------------------------------------------------------

 

表结构如下:

 

(一)使用case when 实现

select * from table3 where
(select case when '&a'=1 then
     (select 1 from dual where xm = 'gao')
 when '&a'=2 then 
     (select 1 from dual where sal = '55.55')
 end from dual)=1;

 

执行输入参数  1  结果 :

输入参数 2   结果:

(二) 使用decode 实现

select * from table3 where decode('&a',1,decode(xm,'gao',1),2,decode(sal,'55.55',1)) = 1;

 

结果同上

0 0