1.while迴圈:
示例:列印數字1-10:
1結果:--使用while迴圈列印數字1-10
2set serveroutput on34
declare5--
定義迴圈變數
6 pnum number :=1;
7begin89
while pnum <=
10loop
10--
迴圈體11
dbms_output.put_line(pnum);
1213
--是變數遞增1
14 pnum := pnum +1;
15end
loop;
1617
end;
18/
![](https://pic.w3help.cc/171/22ea3c9accfce883866f59b35fd62.jpeg)
2.loop 迴圈 【推薦使用,方便用游標】
--使用loop迴圈列印1-10
2set serveroutput on
3declare4--
定義迴圈變數
5 pnum number :=1;
6begin78
loop9--
退出條件:迴圈變數大於10
10exit
when pnum>10;
1112
--列印該變數的值
13dbms_output.put_line(pnum);
1415
--迴圈變數+1
16 pnum := pnum+1;
1718
endloop;
1920
end;
21/結果:
3.for 迴圈
--使用for迴圈列印1-10
2set serveroutput on34
declare5--
定義迴圈變數
6 pnum number :=1;
7begin89
for pnum in
1..10
loop
1011
dbms_output.put_line (pnum);
1213
endloop;
1415
end;
16/結果:
PL SQL學習筆記之迴圈語句
一 基本迴圈 loop 迴圈體 退出迴圈 1 if condition then exit endif 2 exit when condition end loop 二 while迴圈 while condition loop sequence of statements end loop 三 fo...
PL SQL 迴圈控制語句
判斷語句 if.else declare v age number not null 50 beginif0 v age and v age 18 then dbms output.put line 兒童 elsif 18 v age and v age 30 then dbms output.pu...
PL SQL基本迴圈語句
基本迴圈結構包含loop和end loop語句之間的語句序列。通過每次迭代,執行語句序列,然後在迴圈頂部繼續控制。pl sql程式語言的基本迴圈語法是 loop sequence of statements end loop 這裡,語句序列 sequence of statements 可以是單個語...