首页 > Linux操作系统 > Linux操作系统 > oracle case
回答一个网友的问题:
http://www.itpub.net/618756.html
/******************************/
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;
/
__________________
msn:zhouwf0726@hotmail.com
mail:zhouwf0726@163.com
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/756652/viewspace-242152/ ,如需转载,请注明出处,否则将追究法律责任。