ITPub博客

首页 > 数据库 > Oracle > oracle case

oracle case

原创 Oracle 作者:jss001 时间:2009-03-06 19:11:44 0 删除 编辑

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

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;
/

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/18921899/viewspace-1016972/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: number(p,s)
请登录后发表评论 登录
全部评论
  • 博文量
    306
  • 访问量
    871797