Description\n-----------\n\nSyntax\n\n``sql\nLEAVE label\n`\n\nThis statement is used to exit the flow control construct that has the given label. The label must be in the same stored program, not in a caller procedure. LEAVE can be used within BEGIN ... END or loop constructs (LOOP, REPEAT, WHILE). In Stored Procedures, Triggers and Events, LEAVE can refer to the outmost BEGIN ... END construct; in that case, the program exits the procedure. In Stored Functions, RETURN can be used instead.\n\nLEAVE cannot be used to exit a DECLARE HANDLER block.\n\nIf you try to LEAVE a non-existing label, or if you try to LEAVE a HANDLER block, the following error will be produced:\n\n`sql\nERROR 1308 (42000): LEAVE with no matching label: <label_name>\n`\n\nThe following example uses LEAVE to exit the procedure if a condition is true:\n\n`sql\nCREATE PROCEDURE proc(IN p TINYINT)\nCONTAINS SQL\nwhole_proc:\nBEGIN\n   SELECT 1;\n   IF p < 1 THEN\n      LEAVE whole_proc;\n   END IF;\n   SELECT 2;\nEND;\n\nCALL proc(0);\n+---+\n| 1 |\n+---+\n| 1 |\n+---+\n``\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/leave