8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 78%

15.6.2 语句标签15.6.2 Statement Labels

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

[begin_label:] LOOP
    statement_list
END LOOP [end_label]

[begin_label:] REPEAT
    statement_list
UNTIL search_condition
END REPEAT [end_label]

[begin_label:] WHILE search_condition DO
    statement_list
END WHILE [end_label]

使用标签 BEGIN ... END 块,以及对于 LOOP, REPEAT, WHILE 语句。这些语句的标签使用遵循以下规则:Labels are permitted for BEGIN ... END blocks and for the LOOP, REPEAT, and WHILE statements. Label use for those statements follows these rules:

  • begin_label must be followed by a colon.

  • begin_label can be given without end_label。如果end_label is present, it must be the same as begin_label.begin_label can be given without end_label. If end_label is present, it must be the same as begin_label.

  • end_label cannot be given without begin_label.

  • 同一嵌套层级的标签必须是不同的。Labels at the same nesting level must be distinct.

  • 标签长度可达 16 个字符。Labels can be up to 16 characters long.

在标记结构中引用标签时,可以使用 ITERATE 或 LEAVE 语句。以下示例使用这些语句来继续迭代或终止循环:To refer to a label within the labeled construct, use an ITERATE or LEAVE statement. 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;

块标签的作用域不包含块内声明的处理器代码。详情请参见 第 15.6.7.2 节,“DECLARE ...HANDLER 语句“。The scope of a block label does not include the code for handlers declared within the block. For details, see Section 15.6.7.2, “DECLARE ... HANDLER Statement”.