日期:2014-05-17  浏览次数:20852 次

SQL语句中LOOP的问题
loop 
  i<已知数(i为变量,循环次数)
  if(条件) then  
  执行语句1。。。。
   
  不满足条件执行语句2  
  i:=i+1
  
end loop
现在的问题是如果有满足if的条件执行语句1, 我现在想它执行语句1后 i+1然后跳出本次循环继续执行循环语句,相当于for循环中的continue的功能。
  还有哪位大侠能帮我说明下 loop语句中如exit等常见的关键字什么意思么 我刚刚接触存储过程! 感激不尽!

------解决方案--------------------
用起来是一样的,可能语法稍有不同
SQL code
set serverout on
declare
x number;
begin
x:=0;
loop
exit when x>=10;--当x>=10退出循环
x:=x+1;--x每次增加1;
continue when x>5;;--当x>5,进入下次循环
dbms_output.put_line(x);--打印1到5
end loop;
end;

------解决方案--------------------
declare
x number;
begin
x:=0;
loop
exit when x>=10;
x:=x+1;
if x>5 then 
continue;
end if;
dbms_output.put_line(x);
end loop;
end;