PL/SQL CASE

1.CASE中存在selector,不返回值
       declare input_str varchar2(20):=('&str');
       begin
               case input_str
                    when 'A' then dbms_output.put_line(input_str||1);
                    when 'B' then dbms_output.put_line(input_str||2);
                    when 'C' then dbms_output.put_line(input_str||3);
                    when 'D' then dbms_output.put_line(input_str||4);
                    when 'E' then dbms_output.put_line(input_str||5);
                    else dbms_output.put_line('输入未知字符!');
                end case;
       end;

2.CASE中存在selector,作为表达式使用
       declare input_str varchar2(20):=('&str');result_srtvarchar2(50);
       begin
               result_srt:=case input_str
                    when 'A' then input_str||1
                    when 'B' then input_str||2
                    when 'C' then input_str||3
                    when 'D' then input_str||4
                    when 'E' then input_str||5
                    else '输入未知字符!'
                end;
               dbms_output.put_line(result_srt);
       end;
注意: case语句内允许有分号,以end的结束。

3.不使用CASE中的选择器搜索CASE
       declare input_str varchar2(20):=('&str');result_srtvarchar2(50);
       begin
               result_srt:=case
                    when input_str='A'then input_str||1
                    when input_str='B'then input_str||2
                    when input_str='C'then input_str||3
                    when input_str='D'then input_str||4
                    when input_str='E'then input_str||5
                    else '输入未知字符!'
               end;
               dbms_output.put_line(result_srt);
       end;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值