-- Job Permissions
Grant CreateJob tosomebody;
--Job Creation
begin
Dbms_scheduler.create_job (
Job_name= 'Agent_liquidation_job',
Job_type= 'stored_procedure',
Job_action= 'agent_liquidation. Liquidation', --Stored Procedure name
start_date=Sysdate,
Repeat_interval= 'freq=monthly; interval=1; Bymonthday=1; Byhour=1; byminute=0; Bysecond=0', --Monthly , Interval of 1 (months), 1th per month, 1 o'clock in the morning
Comments= 'implementation of agent clearance procedures'
);
End;
/
--Job execution Time Test
DECLARE
Start_date date;
Return_date_after date;
Next_run_date date;
BEGIN
Start_date:=sysdate;--To_timestamp_tz (' 10-oct-2004 10:00:00 ', ' dd-mm-yyyy HH24:MI:SS ');
Return_date_after:=start_date;
forIinch 1..TenLOOP
Dbms_scheduler. Evaluate_calendar_string ('freq=monthly; interval=1; Bymonthday=1; Byhour=1; byminute=0; Bysecond=0', Start_date, Return_date_after, next_run_date);
Dbms_output. Put_Line ('next_run_date:' ||To_char (Next_run_date,'YYYY-MM-DD HH24:MI:SS'));
Return_date_after:=next_run_date;
ENDLOOP;
END;
/
--Job Query
Selectowner, Job_name, state fromDba_scheduler_jobs;
SelectJob_name, State fromUser_scheduler_jobs;
--Job Enable
begin
Dbms_scheduler.enable ('Backup_job');
End;
/
--Job Run
begin
Dbms_scheduler.run_job ('Cola_job', TRUE); --true means synchronous execution
End;
/
--job Stop (not very useful)
begin
Dbms_scheduler.stop_job (Job_name= 'Cola_job', Force=TRUE);
End;
/
--Job deletion (good for stop job)
begin
Dbms_scheduler.drop_job (Job_name= 'Cola_job', Force=TRUE);)
End;
/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Schedule Job for Oracle 10g