- 简单的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;
- 搜索型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;
- 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;