473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 16241
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.