資料庫定時任務

來源:互聯網
上載者:User

標籤:The   bsp   create   int   hat   commit   where   定時   RoCE   

//定時釋放鎖

create or replace procedure p_releaseLockJob
--執行操作的預存程序
is
begin
delete from pub_t_datalocks t where locktime < sysdate - 1/24 ; --處理超過一小時的鎖
end p_releaseLockJob ;
/

 

create or replace procedure p_createRLockJob
--建立任務的預存程序
is
--任務是否已被建立,若任務被建立過,則 isExist > 0
isExist number := 0;
--歸檔任務標識
jobId number;
begin
select count(*) into isExist from all_jobs j where j.what=‘p_releaseLockJob;‘;
--檢查任務是否已被建立,如果已被建立,則不做操作
if isExist = 0 then
--建立任務
dbms_job.submit(jobId, --任務標識
‘p_releaseLockJob;‘, --任務要執行的預存程序
sysdate, --任務開始時間
‘sysdate+1/24‘); -- --任務執行循環,此處指定每周執行一次,執行時間為1小時
commit;

--運行任務

dbms_job.run(jobId);

commit;
end if;
end p_createRLockJob;
/


create or replace procedure p_closeRLockJob
--刪除任務預存程序
is
--任務是否已被建立,若任務被建立過,則 isExist > 0
isExist number := 0;
jobId number;
--歸檔任務標識
begin
select count(*) into isExist from all_jobs j where j.what=‘p_releaseLockJob;‘;
--檢查任務是否已被建立,如果已被建立,則不做操作
if isExist > 0 then
--關閉任務

begin
select job into jobId from all_jobs j where j.what=‘p_releaseLockJob;‘;
dbms_job.remove(jobId);
end ;

commit;
end if;
end p_closeRLockJob;
/

 

call p_createRLockJob(); //啟動定時任務
call p_closeRLockJob(); //關閉定時任務

資料庫定時任務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.