tags:

views:

15

answers:

1

Hello,

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!

+2  A: 

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 ;
Lukáš Lalinský
Thanks!! I think it works now.
Daniel
You are right. +1
NullUserException