zoukankan      html  css  js  c++  java
  • 数据库定时任务

    //定时释放锁

    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(); //关闭定时任务

  • 相关阅读:
    性能测试入门(三)线程组设置详解
    P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper
    P3047 [USACO12FEB]附近的牛Nearby Cows
    P2698 [USACO12MAR]花盆Flowerpot
    P2898 [USACO08JAN]haybale猜测Haybale Guessing
    P1782 旅行商的背包
    P3629 [APIO2010]巡逻
    P1065 作业调度方案
    P1640 [SCOI2010]连续攻击游戏
    P2590 [ZJOI2008]树的统计
  • 原文地址:https://www.cnblogs.com/sx2zx/p/9264496.html
Copyright © 2011-2022 走看看