oracle jobs

1.传统的jobs管理

--查询当前jobs
select * from dba_jobs

select * from all_jobs
create table snowhill(test date)
create or replace procedure myproc as 
begin
  
insert into snowhill values(sysdate);
  
end;
  
select * from dict where table_name like '%JOBS%'

--sumbit a job
variable jobs number;
begin
  dbms_job.submit(:jobs,
'myproc;',sysdate,'sysdate+1/1440');
  
end;
  
  
  
--remove
  begin
  dbms_job.remove(:jobs);
  
end;
  
/

2.10g以后,增了了scheduler。
begin
  dbms_scheduler.create_job
   (
      job_name        => 'JOB_DAY_RECORDS',
      job_type        => 'STORED_PROCEDURE',
      job_action      => 'PRC_DAY_RECORDS',
      repeat_interval => 'FREQ=DAILY; INTERVAL=1',
      START_DATE      => trunc(sysdate)+1+1/240,
      enabled         =>true,
      comments        => '记录每天库新增数据量'
   );
end;

select * from dict where table_name like '%DBA_SCHEDULER%'

TABLE_NAME    COMMENTS
DBA_SCHEDULER_CHAINS    
All scheduler chains in the database
DBA_SCHEDULER_CHAIN_RULES    
All rules from scheduler chains in the database
DBA_SCHEDULER_CHAIN_STEPS    
All steps of scheduler chains in the database
DBA_SCHEDULER_CREDENTIALS    
All scheduler credentials in the database
DBA_SCHEDULER_DB_DESTS    
All destination objects in the database pointing to remote databases
DBA_SCHEDULER_DESTS    
All possible destination objects for jobs in the database
DBA_SCHEDULER_EXTERNAL_DESTS    
All destination objects in the database pointing to remote agents
DBA_SCHEDULER_FILE_WATCHERS    
All scheduler file watch requests in the database
DBA_SCHEDULER_GLOBAL_ATTRIBUTE    
All scheduler global attributes
DBA_SCHEDULER_GROUPS    
All scheduler object groups in the database
DBA_SCHEDULER_GROUP_MEMBERS    Members 
of all scheduler object groups in the database
DBA_SCHEDULER_JOBS    
All scheduler jobs in the database
DBA_SCHEDULER_JOB_ARGS    
All arguments with set values of all scheduler jobs in the database
DBA_SCHEDULER_JOB_CLASSES    
All scheduler classes in the database
DBA_SCHEDULER_JOB_DESTS    State 
of all jobs at each of their destinations
DBA_SCHEDULER_JOB_LOG    Logged information 
for all scheduler jobs
DBA_SCHEDULER_JOB_ROLES    
All scheduler jobs in the database by database role
DBA_SCHEDULER_JOB_RUN_DETAILS    The details 
of a job run
DBA_SCHEDULER_NOTIFICATIONS    
All job e-mail notifications in the database
DBA_SCHEDULER_PROGRAMS    
All scheduler programs in the database
DBA_SCHEDULER_PROGRAM_ARGS    
All arguments of all scheduler programs in the database
DBA_SCHEDULER_REMOTE_DATABASES    List 
of registered remote databases for jobs
DBA_SCHEDULER_REMOTE_JOBSTATE    Remote state 
of all jobs originating from this database
DBA_SCHEDULER_RUNNING_CHAINS    
All steps of all running chains in the database
DBA_SCHEDULER_SCHEDULES    
All schedules in the database
DBA_SCHEDULER_WINDOWS    
All scheduler windows in the database
DBA_SCHEDULER_WINDOW_DETAILS    The details 
of a window
DBA_SCHEDULER_WINDOW_GROUPS    
All scheduler window groups in the database
DBA_SCHEDULER_WINDOW_LOG    Logged information 
for all scheduler windows
DBA_SCHEDULER_WINGROUP_MEMBERS    Members 
of all scheduler window groups in the database

添加一个新的scheduler job

--以scheduler创建轻量级job

create table log_lw(
  user_name varchar2(10),
  user_date date
);

create or replace procedure proc_lw
is
begin
 insert into log_lw(user_name,user_date) values(user,sysdate);
 commit;
end;


BEGIN
        DBMS_SCHEDULER.CREATE_PROGRAM(
                program_name => 'prog_lw',
                program_action => 'proc_lw',
                program_type => 'STORED_PROCEDURE',
                enabled => TRUE
        );
END;


BEGIN
        DBMS_SCHEDULER.CREATE_SCHEDULE(
                schedule_name => 'schedule_lw',
                start_date => SYSTIMESTAMP,
                end_date => SYSTIMESTAMP + 1,
                repeat_interval => 'FREQ=MINUTELY;INTERVAL=1',
                comments => 'Every MINUTELY'
        );
END;


BEGIN
        DBMS_SCHEDULER.CREATE_JOB(
                job_name        => 'lightweight_job',
                program_name    => 'prog_lw',
                schedule_name   => 'schedule_lw',
                job_style       => 'LIGHTWEIGHT'
        );
END;

begin
  dbms_scheduler.enable('lightweight_job');
end;

select job_name,job_style,to_char(start_date,'YYYY-MM-DD hh24:mi:ss') start_date
,repeat_interval,program_name,t.JOB_TYPE,
to_char(t.next_run_date,'yyyy-mm-dd hh24:mi:ss'),sysdate,to_char(t.last_start_date,'YYYY-MM-DD hh24:mi:ss')
  from user_scheduler_jobs t
 
select * from log_lw

       

删除job
begin
  DBMS_SCHEDULER.DROP_JOB
 (
   JOB_NAME   =>'JOB_NAME',
   force =>TRUE);
   end;
如果正在运行需要先停止
begin
 DBMS_SCHEDULER.STOP_JOB (
   job_name=>'JOB_NAME',force =>TRUE
   );
end;
注意用户需要管理job权限:grant manage scheduler to username;否则出ORA-27486:权限不足
相关参考:
http://blog.csdn.net/fw0124/article/details/6753715
 

posted on 2011-08-29 22:25 snowhill 阅读(317) 评论(0)  编辑 收藏 引用 所属分类: 数据库-oracle


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年8月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

公告

又一年...........

留言簿(3)

随笔分类(13)

文章分类(131)

文章档案(124)

c++

java

linux

oracle

常用软件

其他

网络配置

系统安全

音乐

搜索

最新评论

阅读排行榜