--loop
declare
v_i number(5):=1;
begin
loop
dbms_output.put_line(v_i);
EXIT when v_i>=100;
v_i:=v_i+10;
end loop;
end;
set serveroutput on;
declare
v_i number(5):=1;
begin
while v_i<=100 loop
dbms_output.put_line(v_i);
v_i:=v_i+5;
end loop ;
end;
begin
for v_i in reverse 1..100 loop
dbms_output.put_line(v_i);
end loop;
end;
set serveroutput on;
--打印出2-100间的质数
declare
v_i number(5):=2;
v_j number(5):=2;
v_temp number(3):=1;
begin
while v_i<=100 loop
while v_j<=sqrt(v_i) loop
if mod(v_i,v_j)=0 then v_temp:=0;
end if;
v_j:=v_j+1;
end loop;
if v_temp=1 then dbms_output.put_line(v_i);
end if;
v_j:=2;
v_i:=v_i+1;
v_temp:=1;
end loop;
end;
set setveroutput on;
--用for
declare
v_temp number(3):=1;
begin
for v_i in 2..100 loop
for v_j in 2..sqrt(v_i) loop
--mod()条件成立才会执行 then,goto 也是在if 条件中的
if mod(v_i,v_j)=0 then v_temp:=0;
goto label;
end if;
end loop;
<<label>>
if v_temp=0 then dbms_output.put_line(v_i);
end if;
end loop;
end;
set serveroutput on;
打印1-100的自然数,当打印到50的时候 ,瞬间跳出
begin
for i in 1..100 loop
if i=50 then goto label;
end if;
dbms_output.put_line(i);
end loop;
<<label>>
dbms_output.put_line('打印结束');
end;
--也可以 用exist
begin
for i in 1..100 loop
if i=50 then
dbms_output.put_line('打印结束');
EXIT;
end if;
dbms_output.put_line(i);
end loop;
end;
set serveroutput on;
declare
v_i number(5):=1;
begin
loop
dbms_output.put_line(v_i);
EXIT when v_i>=100;
v_i:=v_i+10;
end loop;
end;
set serveroutput on;
declare
v_i number(5):=1;
begin
while v_i<=100 loop
dbms_output.put_line(v_i);
v_i:=v_i+5;
end loop ;
end;
begin
for v_i in reverse 1..100 loop
dbms_output.put_line(v_i);
end loop;
end;
set serveroutput on;
--打印出2-100间的质数
declare
v_i number(5):=2;
v_j number(5):=2;
v_temp number(3):=1;
begin
while v_i<=100 loop
while v_j<=sqrt(v_i) loop
if mod(v_i,v_j)=0 then v_temp:=0;
end if;
v_j:=v_j+1;
end loop;
if v_temp=1 then dbms_output.put_line(v_i);
end if;
v_j:=2;
v_i:=v_i+1;
v_temp:=1;
end loop;
end;
set setveroutput on;
--用for
declare
v_temp number(3):=1;
begin
for v_i in 2..100 loop
for v_j in 2..sqrt(v_i) loop
--mod()条件成立才会执行 then,goto 也是在if 条件中的
if mod(v_i,v_j)=0 then v_temp:=0;
goto label;
end if;
end loop;
<<label>>
if v_temp=0 then dbms_output.put_line(v_i);
end if;
end loop;
end;
set serveroutput on;
打印1-100的自然数,当打印到50的时候 ,瞬间跳出
begin
for i in 1..100 loop
if i=50 then goto label;
end if;
dbms_output.put_line(i);
end loop;
<<label>>
dbms_output.put_line('打印结束');
end;
--也可以 用exist
begin
for i in 1..100 loop
if i=50 then
dbms_output.put_line('打印结束');
EXIT;
end if;
dbms_output.put_line(i);
end loop;
end;
set serveroutput on;