My forum: http://forums.oracle.com/forums/thread.jspa?messageID=1770889 See Advanced Queue for how to use Jobs as multithreading solution See How to crontab to use OS crontab instead of jobs
#jobs created select * from dba_SCHEDULER_JOBS #jobs running select * from dba_scheduler_running_jobs |
Scheduler
create Job Class
#The Job Class is used to identify which service will run the job
#The service may be assigned to a Resource Consumer Group Resource Manager
EXECUTE DBMS_SCHEDULER.CREATE_JOB_CLASS(JOB_CLASS_NAME => 'BATCH_CLASS',
RESOURCE_CONSUMER_GROUP => NULL, SERVICE => 'BATCH_SERVICE', LOGGING_LEVEL => DBMS_SCHEDULER.LOGGING_RUNS,
LOG_HISTORY => 50, > COMMITS => 'Overnight batch');
begin
dbms_scheduler.create_job(
job_name => 'ARC_MOVE_2',
schedule_name => 'EVERY_30_MINS',
--repeat_interval => 'FREQ=MINUTELY; INTERVAL=30',
job_type => 'EXECUTABLE', --STORED_PROCEDURE
job_action => '/home/arup/dbtools/move_arcs.sh',
enabled => true,
number_of_arguments => 4,
job_class => 'BATCH_CLASS' --this is optional, see above
comments => 'Move Archived Logs to a Different Directory');
end;
/ |
dbms_ijob run prvtjob.plb to create dbms_ijob package Setting interval SYSDATE+1: Says to execute a day after the last execution of the job completed TRUNC(SYSDATE)+1+11/24: Keep the job running at 11am every day job fail and broken if a job fail is retried a minute later, if fail is retried 2 minute later, 4, 8, 16, ... 16 subsequents failures the job broken --Important: Use the rule hint on 9i select /*+ RULE */ * from dba_jobs_running |
Create and run
declare
j number;
begin
sys.dbms_job.submit(job => j, what => 'begin insert into p values(to_char(sysdate, ''hh24:mi'')); end;',
next_date => sysdate, interval => 'SYSDATE+1/1440', no_parse => true);
commit;
sys.dbms_ijob.run(j);
end;
begin
--sys.DBMS_IJOB.NEXT_DATE (22, to_date('09/04/2007 09:00', 'dd/mm/yyyy hh24:mi'));
--sys.DBMS_IJOB.BROKEN (22, FALSE, to_date('09/04/2007 09:00', 'dd/mm/yyyy hh24:mi'));
sys.DBMS_IJOB.WHAT (22, 'begin execute immediate ''alter session set sql_trace = true''; PKGICTOPMAINTENANCE.SCHEDULEDINTERCONNECTCREATION; end;');
end;
|
Remove a job
select 'execute dbms_ijob.remove(' || job || ');' from dba_jobs
where what like '%process%'
--Remember that removing a job does not means killing the session,
--the session must be killed manually apart
begin
dbms_ijob.remove(66);
--remember the commit
commit;
end;
|
Get recently broken jobs
declare
cursor c is
select * from dba_jobs where broken = 'Y' and last_date > sysdate - 240/1440;
rc c%rowtype;
begin
open c;
loop
fetch c into rc;
exit when c%notfound;
sys.dbms_system.ksdwrt(2,'ORA-20001 Job ' || rc.job || ' is broken');
end loop;
close c;
end; |
jobs and privileges When a Jnnn process runs a job, the job is run in the same environment in which it was submitted and with the owner’s default privileges. The owner must be explicitly granted the necessary object privileges for all objects referenced within the job definition. When you force a job to run using the procedure DBMS_JOB.RUN, the job is run by your user process and with your default privileges only. Privileges granted to you through roles are unavailable. You must be explicitly granted the necessary object privileges for all objects referenced within the job definition. |