首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

SQL语句中LOOP的有关问题

2012-10-16 
SQL语句中LOOP的问题loopi已知数(i为变量,循环次数)if(条件) then执行语句1。。。。不满足条件执行语句2i:i+

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 ondeclarex number;beginx:=0;loopexit when x>=10;--当x>=10退出循环x:=x+1;--x每次增加1;continue when x>5;;--当x>5,进入下次循环dbms_output.put_line(x);--打印1到5end 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;

热点排行