1、if-then 语句
语法:
if 条件 then
语句序列;
end if;
实例:
declare
i number(2) := 10;
begin
if i < 20 then
dbms_output.put_line('true');
end if;
end;
2、if-then-else 语句
语法:
if 条件 then
语句序列1;
else
语句序列2;
end if;
实例:
declare
i number(2) := 10;
begin
if i < 10 then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
3、if-then-elsif 语句
语法:
if 条件1 then
语句序列1;
elsif 条件2 then
语句序列2;
else
语句序列3;
end if;
实例:
declare
i number(2) := 10;
begin
if i < 10 then
dbms_output.put_line('true1');
elsif i < 20 then
dbms_output.put_line('true2');
else
dbms_output.put_line('false');
end if;
end;
注:可以在一个if-then或if-then-elsif语句中使用另一个if-then或if-then-elsif语句。
4、case 语句
语法:
case selector when 'value1' then 语句序列1; when 'value2' then 语句序列2; when 'value3' then 语句序列3; ... else 语句序列n; -- default case end case;
实例:
declare
sex char(1) := '1';
begin
case sex
when '1' then dbms_output.put_line('男');
when '2' then dbms_output.put_line('女');
else dbms_output.put_line('ry');
end case;
end;
5、搜索 case 语句
语法:
case when selector = 'value1' then 语句序列1; when selector = 'value2' then 语句序列2; when selector = 'value3' then 语句序列3; ... else 语句序列n; -- default case end case;
实例:
declare
sex char(1) := '1';
begin
case
when sex = '1' then dbms_output.put_line('男');
when sex = '2' then dbms_output.put_line('女');
else dbms_output.put_line('ry');
end case;
end;