1

I'm trying to create a simple stored procedure like this:

CREATE DEFINER = 'root'@'localhost'
PROCEDURE testProcedure()
BEGIN

  DECLARE variableAaa INT;
  DECLARE variableBbb INT;

END

but I get this error from MySql:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1

If I change the variable names:

DECLARE variableA INT;
DECLARE variableB INT;

I get error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE variableB INT' at line 1

and so on:

DECLARE variableName INT;
DECLARE variableEmail INT;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE variableEmail INT' at line 1

I'm using MySql 5.5.34 with PhpMyAdmin, but it's the same with Sequel Pro.

Where am I wrong?

1 Answer 1

3

Looks like its an issue of delimiter which you are missing

So the procedure should look like

delimiter //
CREATE DEFINER = 'root'@'localhost'
PROCEDURE testProcedure()
BEGIN

  DECLARE variableAaa INT;
  DECLARE variableBbb INT;

END ; //

delimiter ;

Here I tried the same on MySql and it works

mysql> delimiter //
mysql> create procedure testProcedure()
    -> begin
    -> DECLARE variableAaa INT;
    -> DECLARE variableBbb INT;
    -> end; //
Query OK, 0 rows affected (0.02 sec)

mysql> delimiter ;
Sign up to request clarification or add additional context in comments.

2 Comments

When using phpMyAdmin, I had to begin my code with a delimiter, i.e. ; right before specifying a different delimiter (i.e. //, in this case).
; will be treated as inidividual mysql statements, so to enclose the procedure and statements consist of ; you will need to define a delimiter before the procedure and trigger so that everything inside the delimiter is processed without any confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.