代码改变世界

ORACLE 定时执行存储过程

2017-03-25 10:56  甘雨路  阅读(271)  评论(0编辑  收藏  举报
-- 创建
create table test_lf(
       test_id varchar(40) primary key,
       test_name varchar(50) not null,
       reate_time date
);

select t.*,t.rowid from test_lf t;

--select t.*,t.rowid from lf_201703282003 t
-- 授权
  grant create table to developer
 
-- 创建存储过程
create or replace procedure test_lf_pro
authid current_user
as
tablename varchar(1200);
begin
  -- 拼接数据库名
  select 'LF_' || to_char(sysdate, 'yyyymmddhh24mm') into tablename from dual;
  dbms_output.put_line('执行。。。');
  -- 创建表
  execute immediate  'create table '|| tablename || ' as select * from test_lf where reate_time >(sysdate-1)';
  
end;


-- 调用(手动)
call test_lf_pro();

-- 定时调用
 declare
  jobid number;
  begin
    -- 定时
    --sys.dbms_job.submit(qqid,'LF;',sysdate,'trunc(sysdate+1)+(10*60+45)/(24*60)',true);
    sys.dbms_job.submit(jobid,'test_lf_pro;',sysdate,'trunc(sysdate+1)+11/(24*60)',true);
    commit;
    -- 执行
    dbms_job.run(jobid); 
  end;