`
guochongcan
  • 浏览: 320795 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

SQL 循环执行及间隔多长时间后执行

阅读更多

xxx

 

 

---------------------------------------------------


create table T_CONTINUE_WORK_TEST
(
  TEST_YEAR  NUMBER(4),
  TEST_MONTH NUMBER(2)
);

select * from t_continue_work_test;

truncate table t_continue_work_test;


--倒循环
declare
  test_year number;
  test_month number;
begin
  for test_year in reverse 2010 .. 2016 loop
        for test_month in reverse 1 .. 12 loop
          insert into t_continue_work_test
              (test_year, test_month)
            values
              (test_year, test_month);
              commit;
        end loop;
  end loop;
end;
/

--正循环
declare
  test_year number;
  test_month number;
begin
  for test_year in 2010 .. 2013 loop
        for test_month in 1 .. 12 loop
          insert into t_continue_work_test
              (test_year, test_month)
            values
              (test_year, test_month);
              commit;
        end loop;
        DBMS_LOCK.SLEEP(10);--每10秒插一次
  end loop;
end;
/


---------------------------------------------------

 

 

xxx

 

--通过while 实现
declare
  test_year  int;
  test_month int;
begin
  test_year  := 2010;
  while test_year <= 2014 loop
    test_month := 01;
    while test_month <= 12 loop
      insert into t_continue_work_test
        (test_year, test_month)
      values
        (test_year, test_month);
      commit;
      test_month := test_month + 1;
    end loop;
    test_year := test_year + 1;
  end loop;

end;
/

 

 

xxx

 

--1、ORACLE中的GOTO用法
declare
  x number;
begin
  x := 9;
  <<repeat_loop>> --循环点
  x := x - 1;
  dbms_output.put_line(x);
  if x > 0 then
    goto repeat_loop; --当x的值小于9时,就goto到repeat_loop
  end if;
end;
/


--2、ORACLE中的FOR循环用法
declare
  x number; --声明变量
begin
  x := 1; --给初值
  for x in reverse 1 .. 10 loop
    --reverse由大到小
    dbms_output.put_line('内:x=' || x);
  end loop;
  dbms_output.put_line('end loop:x=' || x); --x=1
end;
/

--3、ORACLE中的WHILE循环用法
declare
  x number;
begin
  x := 0;
  while x < 9 loop
    x := x + 1;
    dbms_output.put_line('内:x=' || x);
  end loop;
  dbms_output.put_line('外:x=' || x);
end;
/


--4、ORACLE中的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('外:x=' || x);
end;
/

 

xxx

 

 

分享到:
评论

相关推荐

    仿世纪佳缘婚介交友系统5.3 ASP+SQL

    仿世纪佳缘婚介交友系统5.3 ASP+SQL Nslove5使用手册 一、运行环境: 1、服务器要求:windows2000及更高系统版本,IIS5+以上! 2、组件要求:Jmail邮件组件、aspjpeg水印组件、上传组件(aspupload组件)、FSO...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    其三、职业方向多:Oracle数据库管理方向、Oracle开发及系统架构方向、Oracle数据建模数据仓库等方向。 四、 如何学习 认真听课、多思考问题、多动手操作、有问题一定要问、多参与讨论、多帮组同学 五、 体系结构 ...

    Excel VBA实用技巧大全 附书源码

    01040设置保存自动恢复文件的时间间隔和保存位置 01041停止屏幕刷新 01042使事件无效 01043使取消键无效 01044不显示警告信息对话框 01045设置使用的打印机 01046安装加载宏 01047利用GetOpenFilename方法获取文件名...

    C#编程经验技巧宝典

    16 &lt;br&gt;0033 Return语句的使用 17 &lt;br&gt;0034 如何实现无限循环 17 &lt;br&gt;0035 巧用foreach语句控制控件 18 &lt;br&gt;0036 有效使用switch case语句 18 &lt;br&gt;2.3 运算符 19 &lt;br&gt;0037 如何使用...

    Oracle9i的init.ora参数中文说明

    说明: 如果值为TRUE, 即使源长度比目标长度 (SQL92 兼容) 更长, 也允许分配数据。 值范围: TRUE | FALSE 默认值: FALSE serializable: 说明: 确定查询是否获取表级的读取锁, 以防止在包含该查询的事务处理被提交...

    C#全能速查宝典

    1.4.43 ToLongTimeString 方法——转换为长时间字符串 87 1.4.44 ToLower方法——转换为小写 87 1.4.45 ToShortDateString方法——转换为短日期字符串 88 1.4.46 ToShortTimeString方法——转换为短时间字符串 88 ...

    易语言程序免安装版下载

     静态编译后的易语言可执行程序(exe)和动态链接库(dll),运行时不再依赖任何支持库文件,文件尺寸更小(相对以前的独立编译),PE结构更合理(取消了“易格式体”),加载速度更快,而且有效解决了“病毒误报”和...

    Access+2000中文版高级编程

    12.3 创建及完善简单的数据访问页 369 12.3.1 数据访问页的字段列表 369 12.3.2 添加超级链接 370 12.3.3 在数据访问页中使用表达式 374 12.3.4 使用绑定的组合框和列表框 375 12.3.5 使用主题格式化 378 ...

    Access 2000中文版高级编程(part1)

    12.3 创建及完善简单的数据访问页 369 12.3.1 数据访问页的字段列表 369 12.3.2 添加超级链接 370 12.3.3 在数据访问页中使用表达式 374 12.3.4 使用绑定的组合框和列表框 375 12.3.5 使用主题格式化 378 12.3...

Global site tag (gtag.js) - Google Analytics