MySQL Forums
Forum List  »  Microsoft SQL Server

Re: Goto Statement
Posted by: Dmitry Tolpeko
Date: February 10, 2009 06:59AM

Hi Arun,

It is better to redesign the code to avoid GOTO-style ( http://en.wikipedia.org/wiki/Goto), but one possible solution is to use LEAVE statement in MySQL

SQL Server code:

CREATE PROCEDURE dbo.spGetProdNum
@Id int
AS
IF @id = 0
GOTO ERR_TRAN

INSERT INTO mess_log VALUES ('Ok')

ERR_TRAN:

INSERT INTO err_log VALUES ('Error')

MySQL code:

CREATE PROCEDURE spGetProdNum(v_Id INT)
BEGIN
ERR_TRAN:
BEGIN
IF v_Id = 0 then
LEAVE ERR_TRAN;
END IF;
INSERT INTO mess_log VALUES('Ok');
END; -- the end of ERR_TRAN block
INSERT INTO err_log VALUES('Error');
END;

Of course, there are some limitations especially for nested GOTOs

--
Kind regards, Dmitry Tolpeko

SQLWays - Converts T/SQL procedures, triggers, scripts from SQL Server/Sybase to MySQL
http://www.ispirer.com

Options: ReplyQuote


Subject
Written By
Posted
July 12, 2007 06:50AM
July 12, 2007 07:58AM
February 07, 2009 01:43AM
Re: Goto Statement
February 10, 2009 06:59AM


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.