您的位置:首页 > 数据库 > Oracle

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

2014-04-10 10:30 741 查看
预热  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;

 

结果同上
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: