Home » SQL & PL/SQL » SQL & PL/SQL » By Setting the Parameter in Seconds can we stop the execution of the program (Oracle ,10g,pl/sql)
By Setting the Parameter in Seconds can we stop the execution of the program [message #432747] Thu, 26 November 2009 00:53 Go to next message
suyogsheth
Messages: 18
Registered: November 2009
Location: Pune
Junior Member
Hi,
I want to write a program(Function). In it i want to start or stop the execution of that program by the entered time.

In this i am going to give tha value by the Parameter. Suppose the PAramaete is pTime is used for entering the value of seconds. If pTime =60( 60 Seconds).
I want that after 60 seconds the program will stop its execution.
Is it possible to do so??
Please reply,its urgent.
Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432751 is a reply to message #432747] Thu, 26 November 2009 01:05 Go to previous messageGo to next message
Michel Cadot
Messages: 63804
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It is not directly possible.
Your procedure has to take start time at the beginning and check from time to time if its own execution exceed the given time and if so stop itself.

Regards
Michel
Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432767 is a reply to message #432751] Thu, 26 November 2009 03:30 Go to previous messageGo to next message
suyogsheth
Messages: 18
Registered: November 2009
Location: Pune
Junior Member
This is the code i have written,
create or replace procedure time_test(pTimeMin in number) is

nSec number;

begin

select (pTimeMin * 60) into nSec from dual;

for i in 1 .. nSec loop
insert into test_time (sr_no, message) values (i, 'This is Record No :' || i);

exit when i > nSec;
end loop;

end time_test;
But its executing in 0.75 Seconds. I have Entered the Parameter = 1Min
According to the requirement this program needs to execute for 60 seconds. after 60 seconds it need to stop its execution.
Is this possible ??
Please help.
Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432771 is a reply to message #432767] Thu, 26 November 2009 03:57 Go to previous messageGo to next message
Michel Cadot
Messages: 63804
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
According to the requirement this program needs to execute for 60 seconds

What does this mean?
If it executes in less that 60 seconds it has to wait before returning?
Or if it executes in more that 60 seconds it aborts and returns?

Regards
Michel
Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432782 is a reply to message #432771] Thu, 26 November 2009 04:44 Go to previous messageGo to next message
suyogsheth
Messages: 18
Registered: November 2009
Location: Pune
Junior Member
Hi,
Thanks for the Reply..

My Requirement is that :
If it executes in 60 seconds it aborts and returns.

If i gave the Parameter Time = 1 Min/60 Sec then
It should exit only when 60 sec is completed.
Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432786 is a reply to message #432782] Thu, 26 November 2009 05:04 Go to previous messageGo to next message
Michel Cadot
Messages: 63804
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
The algorithm is:

begin
  inittime = <get time>
  loop
    <unit work>
    if <get time>-inittime > <duration> then exit; end if;
  end loop;
  if <get time>-inittime < <duration> then 
     sleep <get time>-inittime;
  end if;
end;

Regards
Michel

[Updated on: Thu, 26 November 2009 05:05]

Report message to a moderator

Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432838 is a reply to message #432767] Thu, 26 November 2009 10:17 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
What makes you think one iteration through the loop would take exactly 1 second? (and that there would be no overhead in the rest of the procedure)
Re: By Setting the Parameter in Seconds can we stop the execution of the program [message #432872 is a reply to message #432747] Thu, 26 November 2009 23:11 Go to previous message
Kevin Meade
Messages: 2098
Registered: December 1999
Location: Connecticut USA
Senior Member
Read up on DMBS_UTILITY.GET_TIME. After you understand what this is, you should be able to fix your routine to run for whatever length of time you require.

Good luck, Kevin
Previous Topic: how to update statment if difference between them is greater than 0.1
Next Topic: Passing :NEW as a Record
Goto Forum:
  


Current Time: Mon Sep 26 16:18:40 CDT 2016

Total time taken to generate the page: 0.12164 seconds