Documentation Home
MySQL 9.5 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.4Mb
PDF (A4) - 41.5Mb
Man Pages (TGZ) - 272.3Kb
Man Pages (Zip) - 378.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


15.6.2 Statement Labels

[begin_label:] BEGIN    [statement_list]END [end_label][begin_label:] LOOPstatement_listEND LOOP [end_label][begin_label:] REPEATstatement_listUNTILsearch_conditionEND REPEAT [end_label][begin_label:] WHILEsearch_condition DOstatement_listEND WHILE [end_label]

Labels are permitted forBEGIN ... END blocks and for theLOOP,REPEAT, andWHILE statements. Label use for those statements follows these rules:

  • begin_label must be followed by a colon.

  • begin_label can be given withoutend_label. Ifend_label is present, it must be the same asbegin_label.

  • end_label cannot be given withoutbegin_label.

  • Labels at the same nesting level must be distinct.

  • Labels can be up to 16 characters long.

To refer to a label within the labeled construct, use anITERATE orLEAVE 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;

The scope of a block label does not include the code for handlers declared within the block. For details, seeSection 15.6.7.2, “DECLARE ... HANDLER Statement”.