Sequence of procedures and packages followed in a job - oracle

I have a scheduled job that runs every day. In that job I have called some stored procedures from various packages. I would like to know is there a sequence that is followed in Oracle i.e the sequence in which I have called them or the stored procedure are executed in any random order.

if you're saying you have a single job (vs one job for each SP) that calls packages like
begin
pkgA.procA;
pkgB.procB;
pkgC.procC;
...
end;
then they are executed in the order you have them in the pl/sql anonymous block.
if you have 1 job for each API call though, then they will either execute in parallel or in any random order.

Related

How the jobno generated in DBMS_JOB.submit scheduler

i have the job in my PLSQL package & its returning jobno when i debug , how this job number generated ?
DBMS_JOB.SUBMIT(jobNo, 'begin AsyncContractInvDet_pkg. async_response(JOB); end;');
log_debug('jobNo::::'||jobNo);
How to write equivalent DBMS_scheduler.create for above job and where i can pass jobno as in parameter because my pkg.proc having in parameter
Why does it matter how the number is generated by DBMS_JOB? The only thing that matters is that it is unique.
DBMS_SCHEDULER doesn't use job numbers at all: it identifies jobs by name that you provide and does not generate the identifier for you. See the documentation here for equivalent examples. Scheduled jobs are treated just like other database objects, and in most cases should not be created dynamically. Each job should be defined statically as part of your schema DDL, and only executed dynamically.
You will need to modify your DDL to create named jobs once, just like any other package or stored procedure, then modify your code to use DBMS_SCHEDULER.RUN_JOB to execute jobs by name.

how to call set of procedures in same time without using jobs and chain

I have a package inside package and I have 15 procedures is there but I will run 5 procedures same time,
example: proc1 call---12:22:55
proc2 call---12:22:55
proc3 call---12:22:55
proc4 call---12:22:55
I know that by using chains and jobs it's possible.
Without jobs and chains through front end 1 hit 4 procedures will run at the same time.
I want to start these four procs at the same time.
You can achieve this by using dbms_job
Just create one master procedure which will call all the child procedures parallelly as following:
CREATE OR REPLACE PROCEDURE MASTER_PROC AS
BEGIN
DBMS_JOB.SUBMIT(L_JOB, 'PROC1;');
DBMS_JOB.SUBMIT(L_JOB, 'PROC2;');
DBMS_JOB.SUBMIT(L_JOB, 'PROC3;');
DBMS_JOB.SUBMIT(L_JOB, 'PROC4;');
END MASTER_PROC;
/
Please make sure that job_queue_processes is set to more than four as this parameter decides the maximum number of processes that can be created for the execution of jobs.
Cheers!!

Oracle jobs running into each other

I scheduled three insert procedures at around 3am. The first two were spaced out 10 minutes apart, but the third one was only 5 minutes apart from the second. The third procedure kept failing, and I assumed it might be because the second procedure was still running at the time. All three procedures insert into the same table.
Would the best way to avoid the jobs running into each other be to create a separate procedure that calls the actual inserts in order? Something like this:
CREATE OR REPLACE PROCEDURE DB.DATA_INSERT_ALL IS
BEGIN
EXECUTE DB.DATA_INSERT_1;
EXECUTE DB.DATA_INSERT_2;
EXECUTE DB.DATA_INSERT_3;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
RAISE;
END DATA_INSERT_ALL;
/
What I'm not sure of is: would doing it like this execute each procedure only after the previous is complete (this is what I want)? Or would it try to execute all three at once?
I am doing this on Oracle Express 11g.

How run two or more instances of an oracle job in the same time?

I have defined a function that when it is called it will define an oracle job with
dbms_scheduler.create_job
that runs a store_procedure with arguments
my Function
Begin
job created and executed from here
end;
My problem is that when an instance of my job is executing I can not execute another instance of that job.
as I said my jobs executes a store_procedure that have arguments so I want to execute that job with different values of arguments in the same time but I can not.
is there any property or way that can help me to do this?
Give the jobs you create random names.

Display comments to user while executing Oracle procedure

Is it possible to display comments to user while executing a procedure in a package. My package has 3 procedures. I am calling each one after other. I want to display comments on console like procedure xyz is executing, procedure executed successfully. I added comments inside procedure like DBMS_OUTPUT.PUT_LINE('PROCEDURE EXECUTED SUCCESSFULLY') but didn't worked for me.
FYI i am using oracle 11g in windows 7 system.
You can't use DBMS_OUTPUT to display information on a procedure while it is running. This is because DBMS_OUTPUT.put_line doesn't display data on screen, rather, the data is put in a queue that is later read by the calling client (This queue is also invisible outside of its transaction). If you use SQL*Plus the queue is read and displayed automatically at the end of the procedure if you have SET SERVEROUTPUT ON.
Other means exist to follow the progress of a procedure while it is running:
You could write to a file instead. UTL_FILE.put_line will write directly if the parameter autoflush is set to true.
You could set session variables with DBMS_APPLICATION_INFO. These variables can be read with another session by querying v$session.
You could use AUTONOMOUS_TRANSACTIONS to log progress information in a dedicated table. This table can be queried by another session simultaneously.
As you can see you would need another process to read the information while it is written. In some applications, this would be achieved by running the main batch job in a new separate process, for example by calling DBMS_JOB or DBMS_SCHEDULER while the calling transaction loops on the progress table or file until the job is complete.
SQL*Plus is not an interactive client, you will need some more sophisticated environment to achieve this functionality.

Resources