How can I use transactions in my MySQL stored procedure?

Two syntax errors:

  • You need commas in between the conditions for your exit handler. Notice the syntax documentation shows commas.

  • You need to terminate the END of the exit handler with a semicolon. The DECLARE statement itself (including its BEGIN…END block) is a statement like any other, and need to have a terminator.

So you need this:

DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING
BEGIN
    ROLLBACK;
END;

Leave a Comment