I’m following some tutorials on mysql function creation but I keep getting the following 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 ” at line 5:
CREATE FUNCTION getstatisticscount (h VARCHAR(35),d date)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE tel INT;
SELECT count(hash) into tel from statsitieken where hash=h and lastvisit between concat(d,' 00:00:00') and concat(d,' 23:59:59') group by hash;
RETURN tel;
END;
I can for my life not find where line 5 is, but no matter which line I put it on, I keep getting this error.
If I remove this function from the sql fiddle code it’s all fine.
I can’t find what’s wrong with it… except maybe flawed tutorials.
Use Delimiter
For more info: http://dev.mysql.com/doc/refman/5.1/en/stored-programs-defining.html
Edit: basically since your stored procedure separates out statements with semicolons (;) and the method that defines your procedure ALSO uses semicolons to separate out statements, it’s hard to impossible for MySQL to figure out where your procedure begins and ends.
I also edited the SQL statement above to return the delimiter back to the default semicolon.