您好,登錄后才能下訂單哦!
今天在閑暇時間練習了一下oracle任務計劃,具體詳情如下
1.創建表 TBL_TIME
create table tbl_time( id number not null, /*id號*/ 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 /* 功能描述:在插入數據之前利用seq_tbltime 序列使表tbl_time(id)實現遞增 */ 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 /* 功能描述:在一分鐘之內每過5秒鐘向 表tbl_time插入當前時間點 */ 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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。