[bbk5163]第56集-第6章 - 用scheduler自动化 04
Persistent Lightweight Jobs
Persistent lightweight jobs:
- Reduce the overhead and time required to start a job
- Have a small footprint on disk for the job metadata and for storing run-time data.
- Are created from a job template(in the commad line)
创建lightweight job的语法
BEGIN DBMS_SCHEDULER.CREATE_JOB( job_name => 'lightweight_jobs', program_name => 'prog1', schedule_name => 'schedule1', job_style => 'LIGHTWEIGHT' ); END; /
Choosing the right job:
- Use regular jobs for maximum flexibility
- Use persistent lightweight jobs when you need to create a large number of jobs in a very short time.
如何创建一个轻量级的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; / /* ======================================================================================================= program ======================================================================================================= */ ------------------------------create BEGIN DBMS_SCHEDULER.CREATE_PROGRAM( program_name => 'prog_lw', program_action => 'U2.proc_lw', program_type => 'STORED_PROCEDURE', enabled => TRUE ); END; / ------------------------------drop BEGIN DBMS_SCHEDULER.DROP_PROGRAM( program_name => 'prog_lw' ); END; / /* ======================================================================================================= Schedule ======================================================================================================= */ ------------------------------create 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; / ------------------------------drop BEGIN DBMS_SCHEDULER.DROP_SCHEDULE( schedule_name => 'schedule_lw' ); END; / /* ======================================================================================================= lightweight job ======================================================================================================= */ ------------------------------create BEGIN DBMS_SCHEDULER.CREATE_JOB( job_name => 'lightweight_job', program_name => 'prog_lw', schedule_name => 'schedule_lw', job_style => 'LIGHTWEIGHT' ); END; / ------------------------------drop BEGIN DBMS_SCHEDULER.DROP_JOB( job_name => 'lightweight_job' ); END; / begin dbms_scheduler.enable('lightweight_job'); end; / select job_name,enabled from user_scheduler_jobs; select * from log_lw; /