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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章