[begin_label
:] BEGIN [statement_list
] END [end_label
] [begin_label
:] LOOPstatement_list
END LOOP [end_label
] [begin_label
:] REPEATstatement_list
UNTILsearch_condition
END REPEAT [end_label
] [begin_label
:] WHILEsearch_condition
DOstatement_list
END WHILE [end_label
]
Labels are permitted for BEGIN ... END
blocks and for the LOOP
, REPEAT
, and WHILE
statements. BEGIN ... END
块、LOOP
语句、REPEAT
语句和WHILE
语句允许使用标签。Label use for those statements follows these rules:这些语句的标签使用遵循以下规则:
begin_label
must be followed by a colon.begin_label
后面必须跟一个冒号。
begin_label
can be given without end_label
. begin_label
可以不用end_label
。If 如果存在end_label
is present, it must be the same as begin_label
.end_label
,则必须与begin_label
相同。
如果没有end_label
cannot be given without begin_label
.end_label
,则不能给出begin_label
。
Labels at the same nesting level must be distinct.同一嵌套级别的标签必须是不同的。
Labels can be up to 16 characters long.标签最长可达16个字符。
To refer to a label within the labeled construct, use an 要引用已标记构造中的标签,请使用ITERATE
or LEAVE
statement. ITERATE
语句或LEAVE
语句。The following example uses those statements to continue iterating or terminate the loop:以下示例使用这些语句继续迭代或终止循环:
CREATE PROCEDURE doiterate(p1 INT) BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 < 10 THEN ITERATE label1; END IF; LEAVE label1; END LOOP label1; END;
The scope of a block label does not include the code for handlers declared within the block. 块标签的范围不包括块内声明的处理程序的代码。For details, see Section 13.6.7.2, “DECLARE ... HANDLER Statement”.有关详细信息,请参阅第13.6.7.2节,“DECLARE ... HANDLER语句”。