1.declare
  x number := 60;
begin
  case x
    when 10 then
      dbms_output.put_line('x=10');
    when 20 then
      dbms_output.put_line('x=20');
    when 30 then
      dbms_output.put_line('x=30');
    when 40 then
      dbms_output.put_line('x=40');
    when 60 then
      dbms_output.put_line('x=60');
    else
      dbms_output.put_line('no data');
  end case;
end;

 

2.case的兩種結構

 

SELECT CASE EMPNO
         WHEN 123 THEN
          '2'
         WHEN 321 THEN
          '3'
         ELSE
          '4'
       END EMP
  FROM emp
 
 
  SELECT * FROM EMP
 
 
  SELECT CASE WHEN COMM=12 THEN 'DD'
  WHEN SAL>42000 THEN 'DF' ELSE 'FF' END MA FROM EMP
 

posted on 2009-02-19 14:31  Oracle  阅读(527)  评论(0编辑  收藏  举报