1. While loop
1. Grammar
declare
i number(2) := 1;--定义变量
begin
while 条件判断 loop
dbms_output.put_line(i);--输出语句
i := i+1;--步进表达式
end loop;
end;
2. Examples
3. Output results
2. Exit loop
1. Grammar
--方法二【exit循环】
declare
i number(2) := 1;--定义变量
begin
loop
exit when i > 10;--退出循环条件
dbms_output.put_line(i);--输出语句
i := i+1;--步进表达式
end loop;
end;
2. Examples
3. Output results
Three. For loop
1. Grammar
--方法三【for循环】
declare
--for循环的变量在for语句中定义
begin
for 定义变量名 in 1..10 loop--其中1..10是步进表达式,包含头1和尾10
dbms_output.put_line(i);
end loop;--结束标记
end;
2. Examples
3. Output results
4. Summary
1 ... 10 is a number from 1 to 10, including 1 and 10.
end loop is the end-of-loop marker and must be written.
In addition to the for loop, the other two loops need to define the variable [declare inside].