Monday, April 1, 2013

dbms_scheduler create,schedule,drop a job



create a procedure that is to be scheduled as a job

create or replace procedure insert_employees
as
begin
insert into employees values('aak');
end;
/


create a job and schedule it
begin
dbms_scheduler.create_job(
job_name => 'insertintoemployees2',
job_type => 'stored_procedure',
job_action => 'insert_employees',
start_date => sysdate,
repeat_interval => 'FREQ=DAILY;BYHOUR=4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22;BYMINUTE=0,5,10,15,20,25,30,35,40,45,50,55',
enabled => true,
auto_drop => false );
end;
/


mani>select job_name,state from dba_scheduler_jobs where job_name='INSERTINTOEMPLOYEES2';

JOB_NAME STATE
------------------------------ ---------------
INSERTINTOEMPLOYEES1 SUCCEEDED



drop a job

SQL> begin
2 dbms_scheduler.drop_job('INSERTINTOEMPLOYEES1');
3 end;
4 /

PL/SQL procedure successfully completed.

SQL> select job_name,state from dba_scheduler_jobs where job_name='INSERTINTOEMP
LOYEES1';

no rows selected

SQL>


useful link

No comments: