CASE

  1. 简单的CASE语句
    1 case expression
    2   when result1 then
    3     statement1
    4   when result2 then
    5     statement2
    6   ...
    7   else 
    8     statement_else
    9 end case;
    1 case people --变量
    2   when 'Chinese' then
    3     dbms_output.put_line('你好!');
    4   when 'Spanish' then
    5     dbms_output.put_line('hola');
    6   else 
    7     dbms_output.put_line(q'(s'up)');
    8 end case;
  2. 搜索型CASE语句
    1 case --(true)
    2   when expression1 then
    3        statement1
    4   when expression2 then
    5        statement2
    6   ...     
    7   else 
    8     statement_else
    9 end case;
     1 declare
     2   v_score number := 100;
     3 begin
     4   case
     5     when v_score > 90 then
     6       dbms_output.put_line('A');
     7     when v_score > 80 then
     8       dbms_output.put_line('B');
     9     when v_score > 70 then
    10       dbms_output.put_line('C');
    11     when v_score > 60 then
    12       dbms_output.put_line('D');
    13     else
    14       dbms_output.put_line('E');
    15   end case;
    16 end;
  3. CASE表达式
    1 declare
    2   people varchar2(10) := '天朝人';
    3 begin
    4   dbms_output.put_line(case people
    5                          when '天朝人' then '你好' 
    6                          when 'Spanish' then 'hola' 
    7                          else q'(s'up)' 
    8                          end);
    9 end;
     1 declare
     2   v_score number := 100;
     3 begin
     4   dbms_output.put_line(case
     5                           when v_score > 90 then 'A' 
     6                           when v_score > 80 then 'B' 
     7                           when v_score > 70 then 'C' 
     8                           when v_score > 60 then 'D' 
     9                           else 'E' 
    10                           end);
    11 end;

  

转载于:https://www.cnblogs.com/David-Huang/archive/2013/04/02/2995528.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值