dbms_job package - Examples of using
--ensure that the parameter is set:
job_queue_process = 1

--to invoke a dbms_job to run
exec dbms_job.run(job_id);
exec dbms_job.run(22);

-- Quick test:
create table testdbmsjob (col1 date);

VARIABLE jobno number;
begin
   DBMS_JOB.SUBMIT(:jobno,'insert into testdbmsjob (sysdate)');',to_date('1998-11-20:14:49:00','YYYY-MM-DD:HH24:MI:SS'),'sysdate+1');
   commit;
end;
/
print jobno;


-- DBMS_JOB package to maintain dba_jobs
-- see: Managing Job Queues in Administrator's Guide for more info

-- Query catalog
select job,next_date,interval,next_sec, failures, broken,what, LOG_USER,PRIV_USER,SCHEMA_USER from dba_jobs;

-- Submit nightly scheduled jobs (Job Control)
VARIABLE jobno number;
begin
   DBMS_JOB.SUBMIT(:jobno,'pk_batch_jobs.nightly_scheduler(1);',to_date('1998-12-03:05:00:00','YYYY-MM-DD:HH24:MI:SS'),'sysdate+1');
   commit;
end;
/
print jobno;

-- Altering the job
exec DBMS_JOB.CHANGE( job, what, next_date, interval);
exec DBMS_JOB.CHANGE( 8, null, to_date('1998-12-03:05:00:00','YYYY-MM-DD:HH24:MI:SS'), 'sysdate+1');
exec DBMS_JOB.CHANGE( 21, null, to_date('1998-12-05:05:00:00','YYYY-MM-DD:HH24:MI:SS'), 'sysdate+1');

-- change a job to run @ 5:00am everyday
exec DBMS_JOB.CHANGE( 4, null, to_date('2012-03-28:06:00:00','YYYY-MM-DD:HH24:MI:SS'), 'trunc(sysdate+1)+5/24');

-- Find jobs that are broken
select job, broken, failures from dba_jobs;

-- Un-break a broken job
-- job#, FALSE
exec dbms_job.broken(4,false);

-- Mark job as broken
-- job#, broke(TRUE), date(default is sysdate)
exec dbms_job.broken(21,TRUE,sysdate);


-- Remove a job
exec dbms_job.remove(2);

-- Submit a job for scheduling
-- syntax:
DBMS_JOB.SUBMIT(  job             OUT    BINARY_INTEGER,
                  what            IN     VARCHAR2,
                  next_date       IN     DATE DEFAULT SYSDATE,
                  interval        IN     VARCHAR2 DEFAULT 'null',
                  no_parse        IN     BOOLEAN DEFAULT FALSE)

-- example:
DBMS_JOB.SUBMIT(:jobno,'test_dbstar(1,'' TEST JOB SCHDEDULING '');',to_date('1998-11-20:14:49:00','YYYY-MM-DD:HH24:MI:SS'),'sysdate+1');
VARIABLE jobno number;
begin
   DBMS_JOB.SUBMIT(:jobno,'test_dbstar(1,'' TEST JOB SCHDEDULING '');',sysdate,'sysdate+1/(24*30)');
   commit;
end;
/
print jobno;

trunc(sysdate+1)+(1/24)
test.test_dbstar(7,'this is a test');

-- Submit test
VARIABLE jobno number;
begin
   DBMS_JOB.SUBMIT(:jobno,'test_dbstar(1,'' TEST JOB SCHDEDULING '');',to_date('1998-11-20:14:49:00','YYYY-MM-DD:HH24:MI:SS'),'sysdate+1');
   commit;
end;
/
print jobno;