0

I am trying to learn how procedures work and I get an error and I don't know why.

DELIMITER //
CREATE PROCEDURE producer
(IN marcaMasinii VARCHAR(20))
SELECT DISTINCT producator, AVG(pret) AS medie 
FROM vehicul v
JOIN proprietate p
ON v.id_vehicul = p.nr_vehicul
WHERE producator = marcaMasinii;
END //
DELIMITER ;

CALL producer("Dacia");

I have this procedure and I get an error on the line where "END //" is. The error sounds like this:

"Syntax error, unexpected END, expecting $END."

If I add the "BEGIN", the code looks like:

DELIMITER //
CREATE PROCEDURE producer
(IN marcaMasinii VARCHAR(20))
BEGIN
SELECT DISTINCT producator, AVG(pret) AS medie 
FROM vehicul v
JOIN proprietate p
ON v.id_vehicul = p.nr_vehicul
WHERE producator = marcaMasinii;
END //
DELIMITER ;

CALL producer("Dacia");

The error looks like this:

"Syntax error, unexpected CREATE, expecting END_OF_INPUT or ;"

What's wrong with the syntax? Can someone explain?

1
  • You are missing BEGIN hence END is unexpected Commented May 29, 2014 at 14:44

1 Answer 1

1

Put the BEGIN before SELECT. You need to read http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html first.

Sign up to request clarification or add additional context in comments.

Comments

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.