Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 732 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to wait for 2 seconds?

#1
How does one cause a delay in execution for a specified number of seconds?

This doesn't do it:

WAITFOR DELAY '00:02';

What is the correct format?
Reply

#2
How about this?

WAITFOR DELAY '00:00:02';

If you have "00:02" it's interpreting that as Hours:Minutes.
Reply

#3
[The documentation for `WAITFOR()`][1] doesn't explicitly lay out the required string format.

This will wait for 2 seconds:

WAITFOR DELAY '00:00:02';

The format is `hh:mi:ss.mmm`.

[1]:

[To see links please register here]

Reply

#4
As mentioned in other answers, all of the following will work for the standard string-based syntax.

WAITFOR DELAY '02:00' --Two hours
WAITFOR DELAY '00:02' --Two minutes
WAITFOR DELAY '00:00:02' --Two seconds
WAITFOR DELAY '00:00:00.200' --Two tenths of a seconds

There is also an alternative method of passing it a `DATETIME` value. You might think I'm confusing this with `WAITFOR TIME`, but it also works for `WAITFOR DELAY`.

**Considerations for passing `DATETIME`:**

- It must be passed as a variable, so it isn't a nice one-liner anymore.
- The delay is measured as the time since the Epoch (`'1900-01-01'`).
- For situations that require a variable amount of delay, it is much easier to manipulate a `DATETIME` than to properly format a `VARCHAR`.

**How to wait for 2 seconds:**

--Example 1
DECLARE @Delay1 DATETIME
SELECT @Delay1 = '1900-01-01 00:00:02.000'
WAITFOR DELAY @Delay1

--Example 2
DECLARE @Delay2 DATETIME
SELECT @Delay2 = dateadd(SECOND, 2, convert(DATETIME, 0))
WAITFOR DELAY @Delay2

**A note on waiting for `TIME` vs `DELAY`:**

Have you ever noticed that if you accidentally pass `WAITFOR TIME` a date that already passed, even by just a second, it will never return? Check it out:

--Example 3
DECLARE @Time1 DATETIME
SELECT @Time1 = getdate()
WAITFOR DELAY '00:00:01'
WAITFOR TIME @Time1 --WILL HANG FOREVER

Unfortunately, `WAITFOR DELAY` will do the same thing if you pass it a negative `DATETIME` value (yes, that's a thing).

--Example 4
DECLARE @Delay3 DATETIME
SELECT @Delay3 = dateadd(SECOND, -1, convert(DATETIME, 0))
WAITFOR DELAY @Delay3 --WILL HANG FOREVER

However, I would still recommend using `WAITFOR DELAY` over a static time because you can always confirm your delay is positive and it will stay that way for however long it takes your code to reach the `WAITFOR` statement.
Reply

#5
Try this example:

exec DBMS_LOCK.sleep(5);

This is the whole script:

SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "Start Date / Time" FROM DUAL;

exec DBMS_LOCK.sleep(5);

SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "End Date / Time" FROM DUAL;

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through