Oracle数据库的PL/SQL的流程控制语句

2014-11-24 17:44:15 · 作者: · 浏览: 0

declare
str varchar2(3):='abc';
begin
if(str='abc') then
dbms_output.put_line('abc');
elsif(str='bc') then
dbms_output.put_line('bc');
else
dbms_output.put_line('其他');
end if;
end;


流程控制之循环语句:
简单循环:


--循环控制,简单循环
declare
i number:=0;
begin
loop
i:=i+1;
dbms_output.put_line(i);
if(i=5) then
exit;
end if;
end loop;
end;


嵌套循环:


--循环控制,嵌套循环
declare
i number:=0;
j number:=0;
begin
loop
i:=i+1;
dbms_output.put_line(i);
exit when i=5;
--**********************
j:=0;
loop

j:=j+1;
dbms_output.put_line('abc:'||j);
exit when j=2;

end loop;
--**********************
end loop;
dbms_output.put_line('循环结束');
end;


结果如下:


1
abc:1
abc:2
2
abc:1
abc:2
3
abc:1
abc:2
4
abc:1
abc:2
5
循环结束



推荐阅读: