DOexpr
[,expr
] ...
DO
executes the expressions but does not return any results. DO
执行表达式,但不返回任何结果。In most respects, 在大多数方面,DO
is shorthand for SELECT
, but has the advantage that it is slightly faster when you do not care about the result.expr
, ...DO
是SELECT
的简写,但是它的优点是,当您不关心结果时,它会稍微快一点。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
无效,因为它引用了一个表。