IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    PL/SQL:循环

    Adamhuan发表于 2015-10-09 03:19:37
    love 0

    下面的例子演示在PL/SQL中如何执行循环结构。

    For循环:

    set serveroutput on
    declare
      l_counter number;
    begin
      for l_counter in reverse 1..5
        loop
          dbms_output.put_line('Count is:'||l_counter);
        end loop;
    end;
    /

    运行效果:

    匿名块已完成
    Count is:5
    Count is:4
    Count is:3
    Count is:2
    Count is:1

    While循环:

    set serveroutput on
    declare
      l_counter number;
    begin
      l_counter := 0;
      while l_counter<=10
        loop
          dbms_output.put_line('Counter is:'||l_counter);
          l_counter := l_counter+1;
        end loop;
    end;
    /

    运行效果:

    匿名块已完成
    Counter is:0
    Counter is:1
    Counter is:2
    Counter is:3
    Counter is:4
    Counter is:5
    Counter is:6
    Counter is:7
    Counter is:8
    Counter is:9
    Counter is:10

    ————————————
    Done。



沪ICP备19023445号-2号
友情链接