2

I'm trying to add the following stored procedure to my mysql database:

CREATE PROCEDURE logmsg ( _Username VARCHAR(50), _Message VARCHAR(80) )
BEGIN 
    INSERT INTO chatlogs (sender, message) VALUES (_Username, _Message);
END;

But its failing the query and returning:

#1064 - 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 '' at line 3 

I've been searching for about 2 hours on google and cannot find any answer at all.

Any help is greatly appreciated!

1 Answer 1

2

While I'm not 100% sure because I can't test on a MySQL server at the moment, I think the problem is in the semicolon. On the line with INSERT you basically end the CREATE PROCEDURE statement, which has incorrect syntax this way. You have to set the delimiter to something else (e.g. //), to be able to use the semicolon in the body of the procedure:

delimiter //

CREATE PROCEDURE logmsg ( _Username VARCHAR(50), _Message VARCHAR(80) )
BEGIN 
    INSERT INTO chatlogs (sender, message) VALUES (_Username, _Message);
END//

delimiter ;
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.