oracle學習 迴圈語句

2021-05-22 23:49:43 字數 1093 閱讀 6315

loop迴圈:

create or replace procedure pro_test_loop is

i number;

begin

i:=0;

loop

i:=i+1;

dbms_output.put_line(i);

if i>5 then

exit;

end if;

end loop;

end pro_test_loop;

while迴圈:

create or replace procedure pro_test_while is

i number;

begin

i:=0;

while i<5 loop

i:=i+1;

dbms_output.put_line(i);

end loop;

end pro_test_while;

for迴圈1:

create or replace procedure pro_test_for is

i number;

begin

i:=0;

for i in 1..5 loop

dbms_output.put_line(i);

end loop;

end pro_test_for;

for迴圈2:

create or replace procedure pro_test_cursor is

userrow t_user%rowtype;

cursor userrows is

select * from t_user;

begin

for userrow in userrows loop

dbms_output.put_line(userrow.id||','||userrow.name||','||userrows%rowcount);

end loop;

end pro_test_cursor;

oracle學習 迴圈語句

loop迴圈 create or replace procedure pro test loop is i number begin i 0 loop i i 1 dbms output.put line i if i 5 then exit end if end loop end pro test...

Oracle 迴圈語句

在pl sql中最簡單格式的迴圈語句是基本迴圈語句,這種迴圈語句以loop開始,以end loop結束,其語法如下 loop statement1 exit when condition 注意 當編寫基本迴圈時,一定要包含exit語句,否則pl sql會陷入死迴圈。create table temp...

Oracle迴圈語句

1,當不確定多少次要執行迴圈體並且希望迴圈體至少執行一次,則會使用loop語句 loop 執行每個通過迴圈的 語句 end loop 例項 loop week day 7 exit when week 21 end loop 此時當week值大於21時終止,可以使用exit語句或當遇到exit wh...