oracle pl/sql之sql中的---if语句

pl/sql中为了控制程序的执行方向,引进了if语句,if语句有多种形式

    if....end if 语句 语法如下

        if 条件表达式 then

          pl/sql语句

       end if;

程序演示如下:

SQL> set serveroutput on;
SQL> declare
 a number;
 b number;
 begin
 a:=1;
 b:=2;
 if a>b then
 dbms_output.put_line('a'||'>'||'b');
 else
 dbms_output.put_line('a'||'<'||'b');
 end if;
 end;


a<b
PL/SQL procedure successfully completed

 

if...elslf..elsif...elsif end if 

if 条件表达式 then

pl/sql语句 

elslf 条件表达式2 then

 pl/sql语句2

elslf 条件表达式3 then

 pl/sql语句3

else 

pl/sql语句4

 end if;

 

演示程序:

 

declare
year number:=2016;
flag boolean;
begin
if mod(year,4)<>0 then
flag:=false;
elsif mod(year,100)<>0 then
flag:=true;
elsif mod(year,400)<>0 then
flag:=false;
else
flag:=true;
end if;

if flag then
dbms_output.put_line('闰年');
else
dbms_output.put_line('平年');
end if;
end;

 

结果:

  闰年

PL/SQL procedure successfully completed

 

 

 

 

posted @ 2015-10-20 21:00  逍遥鸣  阅读(2552)  评论(0)    收藏  举报