Creating a oracle to job :
BEGIN
DBMS_SCHEDULER.create_job ( job_name => 'Test_create_job',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN DBMS_STATS.gather_schema_stats(''SCOTT''); END;',-- job action will be procedure which you want to invoke
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=hourly; byminute=0',
end_date => NULL,
enabled => TRUE,
comments => 'Job defined entirely by the CREATE JOB procedure.');
END;
Note : There are many other values for repeat_interval
Stop the Job:
BEGIN
DBMS_SCHEDULER.stop_job (job_name => 'Test_create_job');
END;
Drop the job :
BEGIN
DBMS_SCHEDULER.drop_job (job_name => 'Test_create_job');
END;
Enable job:
BEGIN
DBMS_SCHEDULER.enable (name => 'Test_create_job');
END;
Disable he job:
BEGIN
DBMS_SCHEDULER.disable (name => 'Test_create_job');
END;
Update any job attribute :
BEGIN
DBMS_SCHEDULER.set_attribute (
name => 'Test_create_job',
attribute => 'repeat_interval',
value => 'freq=hourly; byminute=30');
END;
You can check details of the job using follwoing query :
SELECT OWNER, JOB_NAME, JOB_CREATOR, START_DATE, NEXT_RUN_DATE, ENABLED, STATE,REPEAT_INTERVAL FROM dba_scheduler_jobs ds;
No comments:
Post a Comment