if 条件结构
//如果...
if (条件) then ... end if ;
//如果... 否则...
if (条件) then ... else ... end if ;
//多重if
if (条件) then ... elseif then ... else ... end if ;
case
when 条件1 then 结果1 ;
when 条件2 then 结果2 ;
else 其他结果;
end case ;
循环结构
loop… end loop (无线循环) 三要素:初始值,循环条件,循环变量(计算器) 退出:exit
declare
num1 number:=1
begin
loop
dbms_output.put_line(num1||'Hello World');
num1 = num1 + 1 ;
exit when num1 = 11 ;
end loop
end
语法:
declare
1. 初始值
begin
while (2. 条件)
loop
//3. 循环变量
...
end loop;
end
示例:
declare
num1 number:=0 ;
begin
while (num1<10 )
loop
dbms_output.put_line(num1||
num1 := num1+1 ;
end loop ;
end
语法:
begin
for 变量 in 上限 ... 下限;
loop
//语句
...
end loop;
end
示例:
begin
for num1 in 1 ... 10 ;
loop
//打印输出
dbms_output.put_line(num1);
end loop;
end
begin
for num1 in reverse 1 ... 10
loop
//输出的结果就是从大到小
dbms_output.put_line(num1);
end loop;
end