Description\n-----------\n\nSyntax\n\n``sql\nlabel: <construct>\n[label]\n`\n\nLabels are MariaDB identifiers which can be used to identify a BEGIN ... END construct or a loop. They have a maximum length of 16 characters and can be quoted with backticks (i.e.., \\\\\\).\n\nLabels have a start part and an end part. The start part must precede the portion of code it refers to, must be followed by a colon (:) and can be on the same or different line. The end part is optional and adds nothing, but can make the code more readable. If used, the end part must precede the construct's delimiter (;). Constructs identified by a label can be nested. Each construct can be identified by only one label.\n\nLabels need not be unique in the stored program they belong to. However, a label for an inner loop cannot be identical to a label for an outer loop. In this case, the following error would be produced:\n\n``sql\nERROR 1309 (42000): Redefining label <label_name>\n`\n\nLEAVE and ITERATE statements can be used to exit or repeat a portion of code identified by a label. They must be in the same Stored Routine, Trigger or Event which contains the target label.\n\nBelow is an example using a simple label that is used to exit a LOOP:\n\n`sql\nCREATE PROCEDURE test_sp()\nBEGIN\n   my_label:\n   LOOP\n      SELECT 'looping';\n      LEAVE my_label;\n   END LOOP;\n   SELECT 'out of loop';\nEND;\n`\n\nThe following label is used to exit a procedure, and has an end part:\n\n`sql\nCREATE PROCEDURE test_sp()\nmy_label:\nBEGIN\n   IF @var = 1 THEN\n      LEAVE my_label;\n   END IF;\n   DO something();\nEND my_label;\n``\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/labels