user710502
user710502

Reputation: 11471

MySql Stored procedure shows as error in syntax

I am new to creating procedures in mysql, i know how to create them in MSSQL, but i am not sure what is wrong with this, it says Syntax Error Near END

CREATE PROCEDURE GetNameByID(IN CustID INT)
  BEGIN
    SELECT * FROM Customers WHERE CustomerID = CustID
  END

Upvotes: 0

Views: 245

Answers (2)

HighBit
HighBit

Reputation: 278

You are missing the ; at the end of select statement

Upvotes: 0

Bojangles
Bojangles

Reputation: 101473

The query in your procedure needs a semi colon after it:

CREATE PROCEDURE GetNameByID(IN CustID INT)
  BEGIN
    SELECT * FROM Customers WHERE CustomerID = CustID;
  END

You may also need to set the delimiter to something. The MySQL documentation does this:

DELIMITER //

CREATE PROCEDURE GetNameByID(IN CustID INT)
  BEGIN
    SELECT * FROM Customers WHERE CustomerID = CustID;
  END//

(but obviously not with your query)

Upvotes: 1

Related Questions