This 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.
If you try to LEAVE
a non-existing label, or if you try to LEAVE
a HANDLER
block, the following error will be produced:
ERROR 1308 (42000): LEAVE with no matching label: <label_name>
The following example uses LEAVE
to exit the procedure if a condition is true:
CREATE PROCEDURE proc(IN p TINYINT)
CONTAINS SQL
`whole_proc`:
BEGIN
SELECT 1;
IF p < 1 THEN
LEAVE `whole_proc`;
END IF;
SELECT 2;
END;
CALL proc(0);
+---+
| 1 |
+---+
| 1 |
+---+
This page is licensed: GPLv2, originally from fill_help_tables.sql
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4