13.2.3 DO Statement语句

DO expr [, expr] ...

DO executes the expressions but does not return any results. DO执行表达式,但不返回任何结果。In most respects, DO is shorthand for SELECT expr, ..., but has the advantage that it is slightly faster when you do not care about the result.在大多数方面,DOSELECT expr, ...的简写,但是它的优点是,当您不关心结果时,它会稍微快一点。

DO is useful primarily with functions that have side effects, such as RELEASE_LOCK().DO主要用于有副作用的函数,如RELEASE_LOCK()

Example: This SELECT statement pauses, but also produces a result set:示例:此SELECT语句暂停,但也会生成一个结果集:

mysql> SELECT SLEEP(5);
+----------+
| SLEEP(5) |
+----------+
|        0 |
+----------+
1 row in set (5.02 sec)

DO, on the other hand, pauses without producing a result set.:另一方面,DO会暂停而不生成结果集:

mysql> DO SLEEP(5);
Query OK, 0 rows affected (4.99 sec)

This could be useful, for example in a stored function or trigger, which prohibit statements that produce result sets.这可能很有用,例如在存储函数或触发器中,它禁止生成结果集的语句。

DO only executes expressions. DO只执行表达式。It cannot be used in all cases where SELECT can be used. 它不能用于所有可以使用SELECT的情况。For example, DO id FROM t1 is invalid because it references a table.例如,DO id FROM t1无效,因为它引用了一个表。