views:

2010

answers:

4

Modifed.

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 ;

whats wrong with this code? i get following error with it.

There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unknown Punctuation String @ 102 STR: |; SQL: DROP FUNCTION IF EXISTS PersonName;# MySQL returned an empty result set (i.e. zero rows).

DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |; DELIMITER |;

SQL query:

DELIMITER |;

MySQL said: Documentation #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 'DELIMITER |' at line 1

A: 

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 */
Babak Ghahremanpour
now i get #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 'DELIMITER |' at line 1
Basit
OK. Let's try what mikej suggests.
Babak Ghahremanpour
ya i did that as well.
Basit
check the post, i modified with new query and new error.
Basit
A: 

In your last line where you're restoring the delimiter to semicolon you need a space between DELIMITER and ; i.e.

DELIMITER ;
mikej
now getting new error.
Basit
+3  A: 

I would remove the semicolon after END.

    ...
END
|
DELIMITER ;


Re your comment, you can't use the current delimiter when declaring a new delimiter. That sounds confusing, but consider if you do this:

DELIMITER |;

Now MySQL would think the delimiter is "|;" (two characters, a pipe and a semicolon). If you think about it, DELIMITER must be treated in a special way by the MySQL client. It's the only statement that can't be followed by the current delimiter.

So when setting the delimiter to pipe, do this:

DELIMITER |

When setting it back to semicolon, do this:

DELIMITER ;


FWIW, I ran the following with no error on my local test database on MySQL 5.0.75:

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 ;
Bill Karwin
now 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 'DELIMITER |' at line 1
Basit
eaither way its not working..:(
Basit
i have 5.0.67-community-nt and it dont work on it.. dunno why.. i have tried on online server too, which is 5.0.81-community, but it gives me user access denied error on drop table.. the first line.
Basit
actually it worked on 81, but not 67..
Basit
thank you for the help :).. im gonna try some new functions to see the result :)
Basit
+1  A: 

Try this if you are using phpMyAdmin:

http://dotnetfish.blogspot.com/2009/07/1064-you-have-error-in-your-sql-syntax.html

Fai
thank you for the link, its helpful in feature.
Basit