Modifed.
DROP FUNCTION IF EXISTS PersonName;
DELIMITER |;
CREATE FUNCTION PersonName( personID SMALLINT )
RETURNS CHAR(20)
BEGIN
DECLARE pname CHAR
Try this if you are using phpMyAdmin:
http://dotnetfish.blogspot.com/2009/07/1064-you-have-error-in-your-sql-syntax.html
Try this:
DROP FUNCTION IF EXISTS PersonName;
DELIMITER |
CREATE FUNCTION PersonName( personID SMALLINT )
RETURNS CHAR(20)
BEGIN
DECLARE pname CHAR(20) DEFAULT '';
SELECT name INTO pname FROM family WHERE ID=personID;
RETURN pname;
END;
|
DELIMITER ; /* <-- add a space between DELIMITER and the semicolon */
I'm going to throw this in the mix because it may help other people with this issue.
If you are using phpMyAdmin, below the SQL entry box there is a delimiter box where you can type the delimiter to use for the query. You can put the outside delimiter here if you want to and then you don't need the delimiter directives.
For example, if you put the delimiter $$ inside the box you could use the following format for your query.
CREATE FUNCTION
blah blah...
END
$$
Some people may find this easier.
Best solution is, which I tried after getting the above error. The code should be like
Delimiter //
Create function or procedure
Write your function or procedure here...
End (without semicolon)
//
Delimiter ; (semicolon with space)
You have to add delimiter $$
in the beginning and in the last of the mysql script you should to end by the delimiter
I was have problems with the delimiter. I was using Navicat, then I rolled over to MySql workbench and the problem is solved. Workbench inserts the delimiter into code...