PL/SQL Package/Procedure Question [message #602486] |
Wed, 04 December 2013 16:02 |
Duane
Messages: 557 Registered: December 2002
|
Senior Member |
|
|
Not sure if this can be done or not so that's why I'm asking.
Is there a way to have a Package with a Procedure that runs a process/query but returns back to the client right away?
CREATE OR REPLACE PACKAGE Test is
procedure Quick;
end Test;
CREATE OR REPLACE PACKAGE BODY Test as
procedure Quick (Parameter1 in varchar2,
Response out varchar2) is
begin
Insert into a table that takes longer than 3 minutes. Something that takes a long time to process.
Response := 'Your report is running.';
end;
end Test;
So, the client has a time out of 2 minutes but the Procedure runs for more than 3 minutes. Is there a way to call the Procedure and have it return back to the client with some message but have the meat of the Procedure processing away in the Database without having to wait for the Procedure to complete?
I figured this could be done with the Procedure calling a DBMS_JOB to handle the big load but I thought maybe there is a better way of doing this within the actual Procedure. Maybe some statement that performs the work but immediately returns back to the client.
|
|
|
|
|
Re: PL/SQL Package/Procedure Question [message #602498 is a reply to message #602486] |
Thu, 05 December 2013 00:17 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Duane wrote on Thu, 05 December 2013 03:32
Is there a way to have a Package with a Procedure that runs a process/query but returns back to the client right away?
If you are looking for something such that the client gets the first row before function generates the last row then have a look at Pipelined functions
|
|
|
Re: PL/SQL Package/Procedure Question [message #602511 is a reply to message #602486] |
Thu, 05 December 2013 02:42 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
You can get the effect you want by running the procedure through the scheduler:
orclz>
orclz> create or replace procedure slow_proc as begin
2 dbms_lock.sleep(60);
3 end;
4 /
Procedure created.
orclz> exec dbms_scheduler.create_job(job_name=>'run_now',-
> job_type=>'stored_procedure',-
> job_action=>'slow_proc',-
> enabled=>true)
PL/SQL procedure successfully completed.
orclz> select JOB_NAME,ELAPSED_TIME from user_scheduler_running_job
2 ;
select JOB_NAME,ELAPSED_TIME from user_scheduler_running_job
*
ERROR at line 1:
ORA-00942: table or view does not exist
orclz> select JOB_NAME,ELAPSED_TIME from user_scheduler_running_jobs;
JOB_NAME
----------------------------------------------------------------------------
ELAPSED_TIME
---------------------------------------------------------------------------
RUN_NOW
+000 00:00:23.24
orclz> select JOB_NAME,ELAPSED_TIME from user_scheduler_running_jobs;
JOB_NAME
----------------------------------------------------------------------------
ELAPSED_TIME
---------------------------------------------------------------------------
RUN_NOW
+000 00:00:35.81
orclz>
|
|
|
|