plsql控制结构

2010年8月31日 19:51:46

if-then-else语句

declare
a number;
b varchar2(10);
begin
a:=3;
if a=1 then
b:='A';
elsif a=2 then
b:='B';
else
b:='C';
end if;
dbms_output.put_line('b的值是:'||b);
end; 

case语句

declare
a number;
b varchar2(10);
begin
a:=3;
case
when a=1 then b:='A';
when a=2 then b:='B';
when a=3 then b:='C';
else b:='others';
end case;
dbms_output.put_line('b的值是:'||b);
end; 

 循环

if循环

declare

x number;

begin

x:=0;

loop

x:=x+1;

if x>=3

then exit;

end if;

dbms_output.put_line('循环内x的值'||x);

end loop;

dbms_output.put_line('循环外x的值'||x);

end;

when循环

declare
x number;
begin
x:=0;
loop
x:=x+1;
exit when x>=3;
dbms_output.put_line('循环内x的值'||x);
end loop;
dbms_output.put_line('循环外x的值'||x);
end;

while循环

declare
x number;
begin
x:=0;
while x<3 loop
x:=x+1;
dbms_output.put_line('循环内x的值'||x);
end loop;
dbms_output.put_line('循环外x的值'||x);
end;

for循环

begin
for i in 1..5 loop
dbms_output.put_line('i='||i);
end loop;
dbms_output.put_line('end of for loop');
end;

for逆循环

begin
for i in reverse 1..5 loop
dbms_output.put_line('i='||i);
end loop;
dbms_output.put_line('end of for loop');
end;

goto和标号

declare
x number;
begin
x:=0;
<<repeat_loop>>
x:=x+1;
dbms_output.put_line(x);
if x<3 then
goto repeat_loop;
end if;
end; 

原文地址:https://www.cnblogs.com/lanzi/p/1813995.html