case语句,求助高手 几个when分支执行相同操作,怎么合并到一块

case语句,求助高手 

几个when分支执行相同操作,怎么合并到一块
比如:
case selector
when a then A;
when b then A;
when c then B;
when d then B;
when e then C
end case;

/**************************************/


set serverout on

create table test (id varchar2(10));
insert into test values('1');
insert into test values('2');
insert into test values('3');
insert into test values('4');
insert into test values('5');
commit;

declare 
cursor cur_test is select id from test;
begin
for row_cur in cur_test loop
case when row_cur.id='1' or row_cur.id='2' then
dbms_output.put_line('A');
when row_cur.id='3' or row_cur.id='4' then
dbms_output.put_line('B');
else
dbms_output.put_line('C');
end case;
end loop;
end;
/


declare 
cursor cur_test is select id from test;
begin
for row_cur in cur_test loop
dbms_output.put_line(
case when row_cur.id='1' or row_cur.id='2' then
'A'
when row_cur.id='3' or row_cur.id='4' then
'B'
else
'C'
end);
end loop;
end;
/


declare 
cursor cur_test is 
select case 
when id='1' or id='2' then 'A'
when id='3' or id='4' then 'B'
else 'C' end id
from test;
begin
for row_cur in cur_test loop
dbms_output.put_line(row_cur.id);
end loop;
end;
/
posted @ 2011-07-11 21:42  jex  阅读(607)  评论(0)    收藏  举报