if then elsif与select case when

case when

View Code
1  select (case userid
2     when 'CUS0000003017804' then
3       '张三'
4     when 'CUS0000003017805' then
5       '李四'
6     else
7       '王五'
8   end) userid from users a where loginname = 'xxx';
View Code
 1 select case
 2          when userid ='CUS0000003017804' then
 3           '张三'
 4          when userid ='CUS0000003017805' then
 5           '李四'
 6          else
 7           '王五'
 8        end userid
 9   from users a
10  where loginname = 'xxx';

 

//字段中有符合delete等关键字的字段查询出来,不包含的不显示
select (case
         when (instr(sql_text, 'delete') > 0 or
              instr(sql_text, 'update') > 0 or
              instr(sql_text, 'insert') > 0) and
              instr(sql_text, 't_recordsql') > 0 then
          sql_text
         else
          ''
       end),length(sql_text)
  from v$sql a
 where a.LAST_ACTIVE_TIME >=
       to_date('2013/06/04 16:04:05', 'yyyy/mm/dd hh24:mi:ss')
   and a.LAST_ACTIVE_TIME <=
       to_date('2013/06/04 18:04:05', 'yyyy/mm/dd hh24:mi:ss')
 order by length(sql_text) asc
View Code

 

 

if then elsif

View Code
 1 declare
 2   v_sal users.userid%type;
 3   i     integer;
 4 begin
 5   select userid into v_sal from users where loginname = 'zhuqiaoping';
 6   if v_sal = 'zhuqiaoping' then
 7     dbms_output.put_line('张三');
 8   elsif v_sal = 'zhu' then
 9     dbms_output.put_line('李四');
10   else
11     dbms_output.put_line('王五');
12   end if;
13 
14 end;

我到现在发现的区别是,case when不能作为单独的语句块

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值