广告
返回顶部
首页 > 资讯 > 数据库 >oracle触发器、序列、任务计划练习一例
  • 925
分享到

oracle触发器、序列、任务计划练习一例

2024-04-02 19:04:59 925人浏览 独家记忆
摘要

今天在闲暇时间练习了一下oracle任务计划,具体详情如下1.创建表 TBL_TIMEcreate table tbl_time( id number not&nb

今天在闲暇时间练习了一下oracle任务计划,具体详情如下

1.创建表 TBL_TIME

create table tbl_time(

id number not null,    

vsecond varchar2(2),   

vtime varchar2(10)    

)

2.创建序列 seq_tbltime

create sequence seq_tbltime

start with 1

increment by 1

nomaxvalue

nocycle

cache 20

3.创建触发器 tr_tbltimeseq

create or replace trigger tr_tbltimeseq



before insert on tbl_time

for each row

  begin

    select seq_tbltime.nextval into :new.id from dual; 

    end tr_tbltimeseq;

   
4.创建存储过程 proc_addtime

create  or replace procedure proc_addtime



as

d_time1 date;

d_time2 date;

n_timediff number(2);

i number(2);

begin

  select sysdate into d_time1 from dual;

  insert into tbl_time values(1,to_char(d_time1,'ss'),to_char(d_time1,'yyyymmddhhss'));

  i:=5;

  while i<=60 loop

    select sysdate into d_time2 from dual;

    select round(to_number(d_time2 - d_time1) * 24 * 60 * 60) into n_timediff from dual;

    if n_timediff=i  then

          insert into tbl_time values(1,to_char(d_time2,'ss'),to_char(d_time2,'yyyymmddhhss'));

          i:=i+5;

       end if;

    end loop;

     exception 

      when others

        then

          rollback;

     commit;

end;

5.创建任务计划

variable n number;



begin 

    dbms_job.submit(:n,'proc_addtime;',sysdate,'sysdate + 5/(24*60)');

   commit;

end;


执行结果如下

sql> select * from tbl_time;

 

        ID VSECOND VTIME

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

         1 09      201407030509

         2 14      201407030514

         3 19      201407030519

         4 24      201407030524

         5 29      201407030529

         6 34      201407030534

         7 39      201407030539

         8 44      201407030544

         9 49      201407030549

您可能感兴趣的文档:

--结束END--

本文标题: oracle触发器、序列、任务计划练习一例

本文链接: https://www.lsjlt.com/news/41634.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作