Oracle 的幾種循環方式介紹


1 Oracle 中的Goto 用法:

declare
x number;
begin
  x:=10; --定義的初始值
  <<repeat_loop>> --循環點
  x:= x-2; -- 循環的處理條件
  dbms_output.put_line('結果x是:'||x); -- 循環一次打印一次
  if x>0 then
    GOTO repeat_loop; -- 再次循環
 
   else if x<0 then
     dbms_output.put_line('數值是x:'||x);
     end if;
  end if;
end;

2 Oracle中的for循環用法:

declare
begin
   for i in 2..10 Loop
     dbms_output.put_line('結果i是:'||i);
  end loop;
end;

3 Oracle中while的循環用法:

declare
x number;
begin
 x := 5 ;
 while x>0 loop
   x := x-1; -- 循環的每次處理
 if x = 3 then
   return; -- 跳出循環
 else
    dbms_output.put_line('x的值是'||x);
   end if;
 end loop; 
end;

4 Oracle 中的loop循環用法:

declare
x number;
begin
  x:=0;
  loop
    x := x+1;
    exit when x >5 ; -- x大於5是終止
     dbms_output.put_line('結果x是two:'||x);
  end loop;
  end;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM