MySQL 8.0-13.2.3 DO Statement

MySQL的DO语句用于执行表达式,尤其适合有副作用的函数,如RELEASE_LOCK(),它在不需要结果集时比SELECT更快。在存储函数或触发器中,DO能避免产生结果集,而SELECT则可能会导致错误。
DO expr [, 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执行表达式,但不返回任何结果。在大多数情况下,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. 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.

DO只执行表达式。不能在所有可以使用SELECT的情况下使用它。例如,DO id FROM t1无效,因为它引用了一个表。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值