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