MySQL Forums
Forum List  »  Stored Procedures

Re: How do you exit a procedure
Posted by: Roland Bouman
Date: January 06, 2006 01:32PM


The generic way to exit a block is the LEAVE statement: http://dev.mysql.com/doc/refman/5.0/en/leave-statement.html

LEAVE works for BEGIN..END, and also for the various loop constructs. You do need to label your blocks though:

create procedure myproc()
MAIN_BLOCK: begin
declare v_panic bool default false
..
..
if v_panic then
leave MAIN_BLOCK;
end if;
..
..
end MAIN_BLOCK;

(the label after the end is optional, see http://dev.mysql.com/doc/refman/5.0/en/begin-end.html)

other labeled constructs:
http://dev.mysql.com/doc/refman/5.0/en/loop-statement.html
http://dev.mysql.com/doc/refman/5.0/en/repeat-statement.html
http://dev.mysql.com/doc/refman/5.0/en/while-statement.html

BTW If "a condition rises, I need to exit": I fthe condition happens to be an exception, warning or error condition, I feel you should use a HANDLER with an empty statement:

DECLARE EXIT HANDLER FOR [condition] begin end;

see: http://dev.mysql.com/doc/refman/5.0/en/declare-handlers.html



Edited 1 time(s). Last edit at 01/06/2006 01:34PM by Roland Bouman.

Options: ReplyQuote


Subject
Views
Written By
Posted
21194
January 05, 2006 04:38AM
11265
January 05, 2006 12:12PM
Re: How do you exit a procedure
10923
January 06, 2006 01:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.