pl/sql 实例精解 06

1. 简单循环

 

   1:  LOOP
   2:    statement1;
   3:    statement2;
   4:    EXIT WHEN condition;
   5:  END LOOP;
   6:  statement3;

也可以使用 IF 语句来限制 exit 的条件.

if condition then

  exit;

end if;

 

2. while 循环

   1:  while condition loop
   2:    statement1;
   3:    statement2;
   4:    ...
   5:    statementN;
   6:  end loop;

 

3. FOR 数值型循环

   1:  FOR loop_counter IN [REVERSE] lower_limit .. upper_limit LOOP
   2:    statement1;
   3:    statement2;
   4:    ...
   5:    statementN;
   6:  END LOOP;

reverse: 是 5,4,3,2,1 这样倒序

 

注意: 可以在循环体内使用 IF condition then exit 来提前终止循环, 但是这不是好的编程习惯.

posted @ 2014-04-09 09:51  神之一招  阅读(186)  评论(0)    收藏  举报