Introduction to several circulation methods of Oracle

1 Goto usage in Oracle:

declare
x number;
begin
  x:=10; --Defined initial value
  <<repeat_loop>> -- loop point
  x:= x-2; -- the processing condition of the loop
  dbms_output.put_line('result x is: '||x); -- print once in a loop
  if x>0 then
    GOTO repeat_loop; -- loop again

   else if x<0 then
     dbms_output.put_line('The value is x:'||x);
     end if;
  end if;
end;

 

2 For loop usage in Oracle:

 
declare
begin
   for i in 2..10 Loop
     dbms_output.put_line('result i is:'||i);
  end loop;
end;

  

3 The loop usage of while in Oracle:

declare
x number;
begin
 x := 5 ;
 while x>0 loop
   x := x-1; -- each processing of the loop
 if x = 3 then
   return; -- exit the loop
 else
    dbms_output.put_line('The value of x is'||x);
   end if;
 end loop;  
end;

4 Loop usage in Oracle:

declare
x number;
begin
  x:=0;
  loop
    x := x+1;
    exit when x >5 ; -- if x is greater than 5, it terminates
     dbms_output.put_line('result x is two:'||x);
  end loop;
  end;

  

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324435739&siteId=291194637