|
|
Question : Asynchronous execution from an Oracle 8i stored procedure
|
|
I would like to write a stored procedure which would call another stored procedure or function asynchronously. First, of all can it be done in Oracle 8i? What I would like to do is, I would run the first proc. and within the first proc., if there is an Update statement which takes very long, I don't want to wait for it but continue with the execution of the rest of the proc. Once the Update statement is complete, I would like the second proc. to notify the first proc.
Any ideas?
|
Answer : Asynchronous execution from an Oracle 8i stored procedure
|
|
Yes, you can do this with Oracle jobs*. A job is something that can be scheduled to run periodically, or it can be executed on demand. Although you can't have the second proc notify the first proc, you can probably do what you need. You can create as many jobs as you need to run your concurrent tasks. Then you can use the dba_jobs_running table to
Here's how in SQL*Plus:
Set up the job:
VARIABLE jobno1 number; VARIABLE jobno2 number; BEGIN DBMS_JOB.SUBMIT(:jobno1, 'long_procedure_1', null, null); DBMS_JOB.SUBMIT(:jobno2, 'long_procedure_2', null, null); commit; END; / print jobno1 <-- This is the job number Oracle assigned to the job print jobno2 <-- This is the job number Oracle assigned to the job
Your main procedure: DECLARE d_start date; d_last_exec date; BEGIN
select sysdate into d_start from dual;
dbms_job.next_date([job number 1],sysdate); dbms_job.next_date([job number 2],sysdate);
d_last_exec := d_start;
-- Wait for the jobs to finish while (d_last_exec <= d_start) loop dbms_lock.sleep(5);
select min(last_date) into d_last_exec from user_jobs_running where job in ([job number 1], [job number 2]); end loop; end; /
Take a look at http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96612/d_job2.htm#1001490 for more info.
* There are a number of ways you can do this, but I think jobs may be most appropriate.
|
|
|
|
|