以自然数1-10和为例子讲解
1:loop语句
declare
sum1 int:=0;
i int:=0;
begin
loop
i:=i+1;
sum1:=sum1+i;
exit when i=10;
end loop;
dbms_output.put_line('前10个自然数的和是:'||sum1);
end;
2:while语句
declare
sum1 int:=0;
i int:=1;
begin
while i<9 loop
sum1:=sum1+i;
end loop;
dbms_output.put_line('前10个自然数的和是:'||sum1);
end;
3:for语句
declare
sum1 int:=0;
i int;
begin
for i in 1..10 loop
sum1:=sum1+i;
end loop;
dbms_output.put_line('前10个自然数的和是:'||sum1);
end;