?
Solved

Trying to execute the below simple function on Mysql 5.1 - getting error

Posted on 2011-05-12
4
Medium Priority
?
275 Views
Last Modified: 2012-05-11
DELIMITER $$
CREATE FUNCTION MChildren.SLastnameTest()
BEGIN
declare lname varchar(50);
SELECT lastname INTO lname FROM MChildren.Children where children.callid = 583;
return lname
END$$
DELIMITER;
0
Comment
Question by:Jsara
  • 3
4 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 35747850
please post the error message
0
 

Author Comment

by:Jsara
ID: 35747900
THe error message is
"You tried to execute an
empty string. Please type an SQL command into the SQL edit field and execute again".
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 1000 total points
ID: 35748073
I think you're missing a return type.  

Also if you're running it mysql query analyzer use:

      script > create stored procedure/ function > (enter function name) > create function

DELIMITER $$
CREATE FUNCTION `MChildren`.`SLastnameTest` () RETURNS VARCHAR(50)
BEGIN
declare lname varchar(50);
SELECT lastname INTO lname FROM Children where children.callid = 583;
RETURN lname;
END $$
DELIMITER ;

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 35748126
Correction: I dropped a reference to "MChildren" in the SELECT

ie
SELECT lastname INTO lname FROM MChildren.Children where children.callid = 583;
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question