8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 15 条 SQL 语句 / 15.6 复合语句语法 / 15.6.1 BEGIN ... END 复合语句
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

15.6.1 BEGIN ... END 复合语句15.6.1 BEGIN ... END Compound Statement

[begin_label:] BEGIN
    [statement_list]
END [end_label]

BEGIN ... END syntax is used for writing compound statements, which can appear within stored programs (stored procedures and functions, triggers, and events). A compound statement can contain multiple statements, enclosed by the BEGIN以及END keywords. statement_list represents a list of one or more statements, each terminated by a semicolon (;) statement delimiter. The statement_list itself is optional, so the empty compound statement (BEGIN END) is legal.BEGIN ... END syntax is used for writing compound statements, which can appear within stored programs (stored procedures and functions, triggers, and events). A compound statement can contain multiple statements, enclosed by the BEGIN and END keywords. statement_list represents a list of one or more statements, each terminated by a semicolon (;) statement delimiter. The statement_list itself is optional, so the empty compound statement (BEGIN END) is legal.

BEGIN ... END 块可以嵌套。BEGIN ... END blocks can be nested.

使用多个语句需要客户端发送包含 ; 语句分隔符的语句字符串。在mysql 命令行客户端中,此操作由 delimiter。更改 ;例如将语句结尾分隔符(例如改为 //)允许 ;可在程序主体中使用。示例可见 第 27.1 节“定义存储程序”。Use of multiple statements requires that a client is able to send statement strings containing the ; statement delimiter. In the mysql command-line client, this is handled with the delimiter command. Changing the ; end-of-statement delimiter (for example, to //) permit ; to be used in a program body. For an example, see Section 27.1, “Defining Stored Programs”.

A BEGIN ... END 块可以被标记。参见 第 15.6.2 节,“语句标签”。A BEGIN ... END block can be labeled. See Section 15.6.2, “Statement Labels”.

可选的 [NOT] ATOMIC 子句不被支持。这意味着指令块开头不设置事务保存点,且本上下文中使用的 BEGIN 子句对当前事务没有影响。The optional [NOT] ATOMIC clause is not supported. This means that no transactional savepoint is set at the start of the instruction block and the BEGIN clause used in this context has no effect on the current transaction.

Note

在所有存储程序中,解析器将BEGIN [WORK])作为 BEGIN ... END块。在此语境下,使用 START TRANSACTION 代替。Within all stored programs, the parser treats BEGIN [WORK] as the beginning of a BEGIN ... END block. To begin a transaction in this context, use START TRANSACTION instead.