Chinaunix首页 | 论坛 | 博客
  • 博客访问: 52112
  • 博文数量: 23
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 281
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-04 16:00
文章分类

全部博文(23)

文章存档

2014年(19)

2008年(1)

2007年(3)

我的朋友

分类: Oracle

2014-05-10 20:35:32

一、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) |
给主人留下些什么吧!~~