oracle 对返回数据和where进行判断 case when

 

 

1.对返回值进行判断。

select 
        oper.opid,
        oper.user_name,
        oper.user_host,
        case 
        when oper.oper_type = 1  then 'System Manager' 
        when oper.oper_type = 2  then 'USER Manager'
        end case,
        case
        when oper.oper_object_type = 1 then 'User'
        when oper.oper_object_type = 2 then 'Role'
        when oper.oper_object_type = 3 then 'Broker'
        when oper.oper_object_type = 4 then 'QM Manager'
        when oper.oper_object_type = 5 then 'User Group'
        when oper.oper_object_type = 6 then 'Msg Flow'
        when oper.oper_object_type = 7 then 'Queue'
        end case
     
 from esb_log_user_oper oper;

 

 

 

2.对条件值进行判断

select 1 from mps.mps_sent_goods where STORE_NO =(case when 1<2 then '3011' else '3012' end);

 如果条件成立:sql为:select 1 from mps.mps_sent_goods where STORE_NO =3011 。

如果条件不成立:sql为:select 1 from mps.mps_sent_goods where STORE_NO =3012 。

 

 

 

 

 

3.条件进行判断,

declare

  str varchar(10):='null';
begin
commit;
  insert into T_FIRSTPAGE_RESULTS(pt_index) select count(*) from mps.mps_sent_goods where 1=1 and  (( str!='null' and STORE_NO =str  ) or (str='null' and 1 =1 ))  ;
end ; 

 

如果str值为null,拼接的sql为:select count(*) from mps.mps_sent_goods。

如果str值非null,拼接的sql为:select count(*) from mps.mps_sent_goods where  STORE_NO =str。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值