Skip to Main Content
  • Questions
  • problem in working with dbms_job.submit

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, CSR.

Asked: April 08, 2003 - 8:39 am UTC

Last updated: July 08, 2004 - 9:36 am UTC

Version: 8.1.7

Viewed 1000+ times

You Asked

Tom,
Thanks for giving me chance to post a question.
please check the below code.

create table tab1(dt varchar2(100));

create or replace procedure sp1
is

begin
insert into tab1 values(to_char(sysdate,'dd-mon-yyyy:hh24:mi:ss'));
commit;
end ;
/


declare
jn binary_integer;
begin
dbms_job.SUBMIT(jn,'SP1;',sysdate,'sysdate + 1/86400');
dbms_output.put_line(jn);
end;
/

I wrote one stored procedure(SP1) and submitted this to job.I given interval as 1 sec.
But the SP1 is not invoked as per the given interval.
So, I could not see any rows inserted in the table 'tab1'.

I even tried by giving dbms_job.SUBMIT(jn,'SP1;',sysdate,'sysdate + 1');.
And changed the DB server date. This approach also not solved the problem.

Please let me know, what could be the problem.

Thanks in advance.

and Tom said...

Well, I do not see a commit in there -- jobs only go into the queue for real when you commit. that could be it.


I do not know what your job_queue_interval is set to. jobs are run every N seconds depending on what this is set to. In practicality -- every second is a bit overboard. Maybe every 10 seconds or 60 seconds... that could be it (job_queue_interval)

lastly, I don't know what your job_queue_processes is set to -- if that is zero, jobs will NEVER auto-run. it must be set to a number between 0 and 32 in 8i and 0 and 1000 in 9i. If zero, no jobs run. If set to one, one job at a time runs and so on. that could be it.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

CSR, April 09, 2003 - 12:18 am UTC

Fine, Tom it is working.

Thanks

Why commit?

Gabriel, July 08, 2004 - 9:07 am UTC

Hello Tom,

Can you please explain why there is a need for commit with dbms_jobs? I mean, no other package needs a commit...Can you please explain what the commit does in the case of dbms_jobs and why isn't incorporated in the procedures of dbms_job to make it transparent to the users?

Thank you,

Tom Kyte
July 08, 2004 - 9:36 am UTC

everything that is transactional needs a commit.

all dbms_job.submit does is plop a row into a table. In order for that row to be "seen" by other sessions (specifically the job queue process), you need to commit it. Just like any other row in any other table.


It is transparent to end users.

To professional programmers, concerned about things like transactional integrity, it is equally transparent. You should know "in order to make changes permanent, we must commit when our transaction is over"

Imagine if it auto-committed. that would be horrendous.


I don't like the API's that auto-commit (like dbms_mview for example). *I* want to control the transaction from start to finish. Unfortunately, they considered dbms_mview to be more like DDL than an API

lets look at a couple of packages that don't commit and actually change data. packages like dbms_application_info that don't modify persistently stored data *don't count* of course, since there is nothing to "commit"


dbms_alert -- you need to commit to send the signal. imagine if it auto committed. Hmm, could not use it in a trigger to signal a session to re-read data since they would be signaled PRIOR to the row being actually visible!


dbms_aq -- imagine if the sending of a message automagically commited your transaction, what if your transaction consisted of "insert, send message, delete" in that order? it would be unusable.

dbms_job...

dbms_lock...





More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library