not done many MySQL functions before… So, I am looking to have my function count the number of needles in the haystack below. I keep getting:
#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 7
Which is the line with “RETURN,” Here is what I have:
DELIMITER $$
CREATE FUNCTION `str_count`(needle TEXT, haystack TEXT)
RETURNS INT(5)
BEGIN
RETURN (LENGTH(haystack) - LENGTH(REPLACE(haystack, needle, ""))) / LENGTH(needle);
END$$
Never done this kind of function before, so any help is greatly appreciated!
Thanks in advance!
Well, I feel silly. When running this kind of stuff, make sure you define the Delimiter in the phpMyAdmin text box below the SQL textarea… In my case “$$” but it works great now!