472,986 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

Delay between SQL statements in DB2

Hello everybody

Is there a possibility to make a delay between two sql statements,
namely one sql statement is performed, then there is a delay of some
seconds and then rhe next statement is performed.
In sybase database, there is a possibility to do such thing by using
the statement waitfor delay 'hh:mm:dd'
for example:

while(...)
begin
update table
set field_name = <value>
where <condition>

waitfor delay 'hh:mm:dd'
end

If there is such possibility in DB2 I would like to know if it consumes CPU

Thank you ahead
Amos
Nov 12 '05 #1
2 16055
am******@zahav.net.il wrote:
Hello everybody

Is there a possibility to make a delay between two sql statements,
namely one sql statement is performed, then there is a delay of some
seconds and then rhe next statement is performed.
In sybase database, there is a possibility to do such thing by using
the statement waitfor delay 'hh:mm:dd'
for example:

while(...)
begin
update table
set field_name = <value>
where <condition>

waitfor delay 'hh:mm:dd'
end

If there is such possibility in DB2 I would like to know if it consumes
CPU


If I got this right, then you want to have a delay _in_ your SQL statement,
right?

You could either write (a) a simple UDF (user-defined function) which does a
sleep, or (b) you add a loop that just counts something up.

Option (a) would not consume CPU cycles if you use an external programming
language like C/C++ or Java; if you use SQL, then it would consume CPU
cycles like option (b).

An SQL function could look like this:

CREATE FUNCTION delay(sec INTEGER)
RETURNS INTEGER
LANGUAGE SQL
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE now TIMESTAMP;
DECLARE end TIMESTAMP;

SET now = TIMESTAMP(GENERATE_UNIQUE());
SET end = now + sec SECONDS;

WHILE ( now < end ) DO
SET now = TIMESTAMP(GENERATE_UNIQUE());
END WHILE;

RETURN 1;
END
@

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
am******@zahav.net.il wrote:
Hello everybody

Is there a possibility to make a delay between two sql statements,
namely one sql statement is performed, then there is a delay of some
seconds and then rhe next statement is performed. In sybase database,
there is a possibility to do such thing by using the statement waitfor
delay 'hh:mm:dd' for example:

while(...) begin update table set field_name = <value> where
<condition>

waitfor delay 'hh:mm:dd' end

If there is such possibility in DB2 I would like to know if it consumes
CPU

If you mean you are writing a program in some programming language, such
as C or C++, and running on a UNIX-like operating system (such as Linux),
you can do

while (...) {
EXEC SQL
UPDATE table
SET fieldname = :value
WHERE <condition>;
[ought to check return status here]
sleep (3600*hh + 60*mm + ss)
[or 86400*dd + 3600*hh + 60*mm, if that is what you meant]
}

This consumes very little CPU time as the OS will suspend your process
until the sleep() returns. You will need some testing, though, so read
about the sleep function before you use it (it can return before the time
is up under unusual conditions).

--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ Registered Machine 241939.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 09:35:00 up 6 days, 19:16, 3 users, load average: 0.05, 0.08, 0.08

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: webster | last post by:
I have a whole lot of if statements for checkboxes that play sounds if they are selected (an example is as follows) but i want a delay between when each if statement is played. How do i put a time...
7
by: John Thorner | last post by:
Hi, I am creating a new thread for each of the connections to the server: public class Node_C { .... while (listening) { Socket client_socket = server_socket.accept(); Node_CThread node ...
14
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on...
1
by: ST | last post by:
Hi, I'm trying to debug someone else's code, and I'm going thru this Select Case statement. I'm having problems with the "OTHER" case...in that when the first line of the case is false, it jumps...
1
by: Ricky | last post by:
Hi, I am trying to create this rollover bar menu with js and it works fine until it has to disappear I wanted it to disappear after the mouseout function and after a little delay but instead it...
16
by: ram0812 | last post by:
Helo guys, I am trying to query the MSSQL DB using ADO. I am not able to make the LIKE statement fetch the correct results. Can anyone tell me what I need to do to get this working? Below is the...
3
by: questionit | last post by:
How to set a delay between 2 statements. If i want to put a delay b/w 2 commands, e.g Open Form Wait 1 min Close form
4
by: coolsti | last post by:
I have an applet that accepts data as a stream from a php script using the following code snippet: String dataendpoint = "http://phpfunction.php"; URL url = new...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.