Branching in stored procedures

Analytics
Enthusiast

Branching in stored procedures

All,

Is there any way to perform branching to a specific label in stored procedure. Based on my input value i have to execute one part of my code and stop my execution. Please let me know how this can be achieved.

Thanks,
Arun
1 REPLY
rgs
Enthusiast

Re: Branching in stored procedures

Use the LEAVE control statement to exit a compound block.

CREATE PROCEDURE mysqlsp(IN options INTEGER)

BEGIN

DoWork: BEGIN
-- test option
IF options IS NULL THEN LEAVE DoWork; END IF;
-- do SQL here
END DoWork; -- label name optional here

-- cleanup code here

END;