Oracle中的sql腳本語言中的循環語句介紹


--sql腳本語言的循環介紹:
--1.goto循環點。
declare
  x number;
begin
  x:=0;--變量初始化;
  <<repeat_loop>>--設置循環點。
  x:=x+1;
  dbms_output.put_line(x);--循環體
  if x<9 then            --進入循環的條件。
    goto repeat_loop;   --用goto關鍵字引導進入循環。
    end if;
end;

--2.for循環。

declare
    x number;
begin
  x:=1;
  --reverse 是指從大到小取值。

  for x in  reverse 1 .. 10 loop   --設定x變量取值范圍在1到10之間。for關鍵字提供進入循環的條件,loop關鍵字開始循環。
    dbms_output.put_line('x='||x);
    end loop;
    dbms_output.put_line('end loop x='||x);
end;
--3.while循環。

declare
    x number;
begin
  x:=0;
  while x<9 loop   --while關鍵字提供循環的條件。loop關鍵字開始循環。
    x:=x+1;
    dbms_output.put_line('x='||x);
    end loop;
  dbms_output.put_line('end loop x='||x);
end;

--4.loop循環。

declare
  x number;
begin
  x:=0;
  loop
    x:=x+1;
    exit when x>9;  --終止循環的條件。
    dbms_output.put_line('x='||x);
    end loop;
    dbms_output.put_line(' end loop x='||x);
end;


免責聲明!

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



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