Thursday 6 March 2014

Playing with dbms_jobs

create job
From TOAD and PL/SQL developer you can generate create job statement.









In sql developer you can't generate create job statement.





On sqlplus level using get_ddl you can generate create job statement

variable job number;
begin
  sys.dbms_job.submit(job => :job,
                      what => 'Proc_Dashboard(1,next_date,job);',
                      next_date => to_date('04-01-2013 12:00:00', 'dd-mm-yyyy hh24:mi:ss'),
                      interval => 'SYSDATE+3/1440');
  commit;
end;
/

select * from dba_jobs order by schema_user

DBA_JOBS_RUNNING lists all jobs that are currently running in the instance.

SID                Identifier of process that is executing the job. See "V$LOCK".
JOB                  Identifier of job. This job is currently executing.
FAILURES               Number of times this job started and failed since its last success.
LAST_DATE               Date that this job last successfully executed.
LAST_SEC                  Same as LAST_DATE. This is when the last successful execution started.
THIS_DATE              Date that this job started executing.
THIS_SEC              Same as THIS_DATE. This is when the last successful execution started.
INSTANCE NUMBER        Indicates which instance can execute or is executing the job; the default is 0.


Jobs that are currently running:

SELECT * FROM user_jobs_running;

Loging to perticular schmeas and remove the jobs
========================================
 NEXT_DATE
You can alter the next date that Oracle executes a job by calling the DBMS_JOB.NEXT_DATE procedure,
as shown in the following example:

BEGIN
DBMS_JOB.NEXT_DATE(2, SYSDATE + 3/1400);
commit;
END;
/

INTERVAL
The following example illustrates changing the execution interval for a job by calling the DBMS_JOB.INTERVAL procedure:

BEGIN
DBMS_JOB.INTERVAL(41, 'SYSDATE + 4/1400');
commit;
END;
/

BEGIN
DBMS_JOB.BROKEN(41,TRUE);
commit;
END;
/

BEGIN
DBMS_JOB.REMOVE( 41);
commit;
END;
/



To run the job manually
EXEC dbms_job.run(job_no);

No comments:

Post a Comment