13.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). BEGIN ... END语法用于编写复合语句,它可以出现在存储程序(存储过程和函数、触发器和事件)中。A compound statement can contain multiple statements, enclosed by the BEGIN and END keywords. 复合语句可以包含多个语句,用BEGINEND关键字括起来。statement_list represents a list of one or more statements, each terminated by a semicolon (;) statement delimiter. statement_list表示一个或多个语句的列表,每个语句以分号(;)结尾语句分隔符。The statement_list itself is optional, so the empty compound statement (BEGIN END) is legal.statement_list本身是可选的,因此空的复合语句(BEGIN END)是合法的。

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

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. mysql命令行客户机中,这是通过delimiter命令处理的。Changing the ; end-of-statement delimiter (for example, to //) permit ; to be used in a program body. 改变结束语句分隔符;(例如对于//)允许;在程序体中使用。For an example, see Section 25.1, “Defining Stored Programs”.有关示例,请参阅第25.1节,“定义存储程序”

A BEGIN ... END block can be labeled. BEGIN ... END可以加标签。See Section 13.6.2, “Statement Labels”.请参阅第13.6.2节,“语句标签”

The optional [NOT] ATOMIC clause is not supported. 不支持可选的[NOT] ATOMIC子句。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.这意味着在指令块的开始处没有设置事务保存点,并且在此上下文中使用的BEGIN子句对当前事务没有影响。

Note注意

Within all stored programs, the parser treats BEGIN [WORK] as the beginning of a BEGIN ... END block. 在所有存储程序中,解析器将BEGIN [WORK]视为BEGIN ... END块的开头。To begin a transaction in this context, use START TRANSACTION instead.要在此上下文中开始事务,请改用START TRANSACTION