[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. BEGIN
和END
关键字括起来。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 在mysql命令行客户机中,这是通过delimiter
command. 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
子句对当前事务没有影响。
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
。