8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

15.2.3 DO 语句15.2.3 DO Statement

DO expr [, expr] ...

DO 执行表达式但不返回任何结果。在大多数方面,DO 是 SELECT expr, ...,但其优点是当你不在意结果时会稍微快一些。DO executes the expressions but does not return any results. 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.

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

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

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

DO则暂停但不产生结果集。:DO, on the other hand, pauses without producing a result set.:

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 仅执行表达式。在所有可以使用 SELECT例如,DO id FROM t1 无效,因为它引用了某个表。DO only executes expressions. It cannot be used in all cases where SELECT can be used. For example, DO id FROM t1 is invalid because it references a table.