一、PL/SQL分支结构:
1、作用:分支结构是PL/SQL程序语言的基本结构,它实现了条件的逻辑判断,使得PL/SQL功能更加强大。
2、要求:
1)分支条件
3、说明:
1)在end if后必须要加上分号“;”(英文输入模式下的).如:end if;
2)在每个语句结束时,末尾需要加上分号“;”(英文输入模式下的).
二、分支结构:
分支结果是指程序在执行过程中,会根据的条件进行有选择的性的运行不同的代码块。
语法Ⅰ:
if (条件) then //条件的格式和SELECT语句中,WHERE的条件格式相同。
...
end if; //end if 后必须有分号‘;’(在英文输入模式下的)。
实例:
declare
x number not null := 30;
begin
if ( x <= 50 ) then --当 X <=50时执行下面的代码,否则退出。
dbms_output.put_line( '****************************');
dbms_output.put_line( 'x < 50');
end if;
end;
语法Ⅱ:
if (条件) then
...
else
...
end if; //end if 后必须有分号‘;’(在英文输入模式下的)。
实例:
declare
x number not null := 60;
begin
if ( x <= 50 ) then
dbms_output.put_line( 'x < 50');
else
dbms_output.put_line( '****************************');
dbms_output.put_line( ' 50 < x < 100');
end if;
end;
语法Ⅲ:
if (条件) then
...
elsif (条件) then
...
else
...
end if; //end if 后必须有分号‘;’(在英文输入模式下的)。
实例:
declare
x number not null := 100;
begin
if ( x <= 50 ) then
dbms_output.put_line( 'x < 50');
elsif ( 50 < x and x < 100 ) then
dbms_output.put_line( ' 50 < x < 100');
else
dbms_output.put_line( '****************************');
dbms_output.put_line(' x > =100 ');
end if;
end;
阅读(284) | 评论(0) | 转发(0) |