Delays processing for the current connection for a specified
amount of time or until a given time.
Syntax
WAITFOR {
DELAY <time_value> | TIME <time_value> }
[ CHECK EVERY <integer> }
[ AFTER MESSAGE BREAK ]
Parameters
(back to top)
- DELAY processing is suspended for the given <time_value> interval.
- TIME processing is suspended until the server time
reaches the <time_value>
specified.
- CHECK EVERY controls how often the WAITFOR statement wakes up. By default, WAITFOR wakes up every 5 seconds. The value
is in milliseconds, and the minimum value is
250milliseconds.
- AFTER MESSAGE BREAK the WAITFOR
statement can be used to wait for a message from another connection. In most
cases, when a message is received it is forwarded to the application that
executed the WAITFOR statement and the
WAITFOR statement continues to wait.
If the AFTER MESSAGE BREAK clause is specified, when a message is received
from another connection, the WAITFOR
statement completes. The message text is not forwarded to the application,
but it can be accessed by obtaining the value of the MessageReceived
connection property.
Examples
(back to top)
- Example 1 wait for three seconds:
- Example 2 wait for 0.5 seconds (500 milliseconds):
WAITFOR DELAY '00:00:00:500'
- Example 3 wait until 8 p.m.:
Usage
(back to top)
The WAITFOR statement wakes up
periodically (every 5 seconds by default) to check if it has been canceled or if
messages have been received. If neither of these has happened, the statement
continues to wait.
If the current server time is greater than the time specified,
processing is suspended until that time on the following day.
WAITFOR provides an alternative to
the following statement, and might be useful for customers who choose not to enable
Java in the
database:
call java.lang.Thread.sleep( <time_to_wait_in_millisecs> )
In many cases, scheduled events are a better choice than using
WAITFOR TIME, because scheduled events
execute on their own connection.
Side Effects
- The implementation of this statement uses a worker thread
while it is waiting. This uses up one of the threads specified by the -gn
server command line option.
Standards
(back to top)
- SQL—Vendor extension to ISO/ANSI SQL grammar.
- SAP Database products—This statement is also
implemented by SAP ASE.