ID EN
Miscellaneous Functions

SLEEP(duration)

MySQL 8.4 🇮🇩 Bahasa Indonesia

Tidur (jeda) selama jumlah detik yang diberikan oleh argumen durasi, lalu mengembalikan 0. Durasi mungkin memiliki bagian pecahan. Jika argumennya NULL atau negatif, SLEEP() menghasilkan peringatan, atau kesalahan dalam mode SQL ketat.

Syntax

MYSQL
SELECT SLEEP(1000);
+-------------+
| SLEEP(1000) |
+-------------+
|           0 |
+-------------+

Contoh

Example

When sleep returns normally (without interruption), it returns 0:

MYSQL
SELECT SLEEP(1000);
+-------------+
| SLEEP(1000) |
+-------------+
|           0 |
+-------------+
Example 2

When SLEEP() is the only thing invoked by a query that is interrupted, it returns 1 and the query itself returns no error. This is true whether the query is killed or times out:

MYSQL
SELECT SLEEP(1000);
+-------------+
| SLEEP(1000) |
+-------------+
|           1 |
+-------------+
Example 3

This statement is interrupted using KILL QUERY from another session:

MYSQL
SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(1000);
+-------------+
| SLEEP(1000) |
+-------------+
|           1 |
+-------------+
Example 4

This statement is interrupted by timing out:

MYSQL
SELECT 1 FROM t1 WHERE SLEEP(1000);
ERROR 1317 (70100): Query execution was interrupted
Example 5

When SLEEP() is only part of a query that is interrupted, the query returns an error:

MYSQL
SELECT /*+ MAX_EXECUTION_TIME(1000) */ 1 FROM t1 WHERE SLEEP(1000);
ERROR 3024 (HY000): Query execution was interrupted, maximum statement
execution time exceeded