In Oracle database operations, sometimes we need to execute certain stored procedures on a regular basis. How does Oracle do that? Starting with Oracle version 10.1, Oracle has developed a new package dbms_scheduler. This package will help solve the problem of our scheduled tasks.
A. New Job
1. Job creation Instance
BEGIN
Dbms_scheduler. Create_job (job_name => ' job_exwh_bpartner_static ', Job_type => '
plsql_block ', job_action => ')
DECLARE
io_row number;
Io_status number;
Vo_sqlerr VARCHAR2 (1000);
BEGIN
-Call stored procedure
bi_dm. P_f_t_exwh_bparner_static (Sysdate, Io_row, Io_status, vo_sqlerr);
End; ',
repeat_interval => ' freq=daily; byhour=15; byminute=00; Bysecond=00;interval=1 ',
job_class => ' Default_job_class ',
ENABLED => TRUE,
auto_drop => FALSE,
COMMENTS => ' This is a test ');
End;
2.job StatementDbms_scheduler. Create_job
3.job ParametersJob_name:job name Job_type:job type Plsql_block: Indicates that the task executes a Pl/sql anonymous block. Stored_procedure: Indicates that task execution is a stored procedure. Executable: Indicates that the task performs an external program, such as an operating system command. CHAIN: Indicates that the task executes a CHAIN. Job_action:job Execution Action Repeat_interval:job Schedule Job_class: Specifies the CLASS to which the task is associated, and the default value is Default_job_class ENABLE: Check JOB validity when created Auto_ Drop: The job will be automatically deleted after the job completes or automatically disabled COMMENTS: Memo start_date:job effective time End_date:job end time
4.repeat_interval ParametersFreq:yearly: In the Year Unit Monthly: in the month unit WEEKLY: in the week Unit daily: In the day unit hourly: In the hour unit minutely: in the unit secondly: in the second unit INTERVAL: execution times ByMonthDay : Date in the month Byday: Week Byhour: Hours Byminute: minutes Bysecond: sec
two. Query Job
--Query the user for all job
select * from User_scheduler_jobs;
--Query the running job
select * from User_scheduler_running_jobs
three. Run Job
BEGIN
dbms_scheduler.run_job (use_current_session =>false, job_name => ' job_exwh_bpartner_static ');
End;
four. Delete Job
BEGIN
dbms_scheduler.drop_job (job_name=> ' job_exwh_bpartner_static ', force=>false);
End;
Force: If it is FALSE, if there are other jobs that are using this schedule will not delete this schedule, if it is TRUE if no other job use this schedule will delete this schedule.