Friday, March 18, 2016

Create, Modify, Remove Oracle Scheduler Jobs and Queues.

# Some useful Queries to check the status of Jobs and Queues.
SQL> select job, schema_user, last_date, next_date, interval,failures,broken from dba_jobs where job=613;
SQL> SELECT r.sid, r.job, r.this_date, r.this_sec FROM dba_jobs_running r,dba_jobs j WHERE r.job = j.job;
SQL> select job,LOG_USER,SCHEMA_USER,NEXT_DATE,NEXT_SEC,INTERVAL,FAILURES,BROKEN from dba_jobs where job in (243,244);

SQL> select ACTUAL_START_DATE from ALL_SCHEDULER_JOB_RUN_DETAILS order by ACTUAL_START_DATE desc;
SQL> select OWNER,JOB_NAME, STATUS from ALL_SCHEDULER_JOB_RUN_DETAILS where owner != 'SYS';

SQL> select OWNER,JOB_NAME from DBA_SCHEDULER_JOBS where owner != 'SYS';
SQL> select * from DBA_QUEUE_SCHEDULES where qname='SBL_PTCL_IN_Q';
SQL> select * from DBA_SCHEDULER_JOB_RUN_DETAILS where job_name='SBL_PTCL_IN_Q';


# Create, run and drop of Scheduler Job with example
DECLARE
  Y NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
  ( job       => Y
   ,what      => 'begin
 ctms_operation.update_site_score;
 CTMS_OPERATION.generate_xml;
 end;'
   ,next_date => SYSDATE
   ,interval  => 'NEXT_DAY(TRUNC(SYSDATE),''SATURDAY'')+ 5/24'
   ,no_parse  => FALSE
  );
  DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(Y));
 COMMIT;
END;
/
SQL> select to_char(NEXT_DAY(TRUNC(SYSDATE),'SATURDAY')+ 5/24,'DD-MM-YYYY:HH:MI:SS') from dual;


# Run, Remove, Broken Operation on Job
SQL> exec dbms_job.run(613);
SQL> exec dbms_job.remove(243);
SQL> exec dbms_job.broken(314,FALSE);
SQL> exec dbms_ijob.broken(27,true);

SQL> DBMS_SCHEDULER.DROP_JOB (job_name => 'STATISTICS_COLUMNS_JOB');
SQL> begin dbms_aqadm.start_queue (queue_name => 'SBL_CONTACT_Q', enqueue => TRUE , dequeue => FALSE); end;
SQL> begin dbms_aqadm.start_queue (queue_name => 'SBL_CONTACT_Q', enqueue => FALSE, dequeue => TRUE); end;

# Please visit Below link to know more with examples.

Link1:  http://www.idevelopment.info/data/Oracle/DBA_tips/SQL/SQL_4.shtml
Link2:  http://www.mandsconsulting.com/oracle-dbms_scheduler-vs-dbms_job-create-run-monitor-remove