Oracle loop、while、for循环

  • Loop循环
Declare
  p_sum number := 0;
  p_i number;
Begin
  p_i := 1;
  Loop
    p_sum := p_sum + p_i;
    p_i := p_i + 1;
    If (p_i > 100) then 
      SYS.Dbms_Output.Put_Line(p_sum); Exit;
    End if;
  End loop;
End;  
  • while循环
Declare
  p_sum number := 0;
  p_i number;
Begin
  p_i := 1;
  While p_i <= 100 loop
    p_sum := p_sum + p_i;
    p_i := p_i + 1;
  End loop;
  Dbms_Output.Put_Line(p_sum);
End;  
  • for循环
Declare
  p_sum number := 0;
  p_i number;
Begin
  p_i := 1;
  For p_i in 1..100 loop
    p_sum := p_sum + p_i;
  End loop;
  Dbms_Output.Put_Line(p_sum);
End;  




没有高深的知识,没有进阶的技巧,万丈高楼平地起~!

原文地址:https://www.cnblogs.com/aaron911/p/7777735.html