Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Stored Function Question note the table and columns  are verified

Posted on 2011-09-02
7
Medium Priority
?
320 Views
Last Modified: 2012-05-12
Can anyone tell me what is wrong with this simple stored function in MySQL?
CREATE FUNCTION lup_t1(sid int(12) ) RETURNS text DETERMINISTIC
BEGIN
        DECLARE a1 text;
        SELECT  abstract into a1 from notestbl where Id=sid;
        RETURN a1;
END;

Does MySQL 5.x not allow returning Text types? What is going on
Does MySQL 5.x not allow returning certain large text types
0
Comment
Question by:Robert Silver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Accepted Solution

by:
pivar earned 1000 total points
ID: 36475949
Hi,

Try the following:

DELIMITER //
CREATE FUNCTION lup_t1(sid int(12) ) RETURNS text DETERMINISTIC
BEGIN
        DECLARE a1 text;
      SELECT  abstract into a1 from notestbl where Id=sid;
        RETURN a1;
END
//

/peter
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36476689
I have seen a bug report from long ago on TEXT that was too long. How large is the data?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36476707
I could not reproduce the old bug in 5.5 MySQL by the way. Without further information, I would have to agree with Peter that likely you just need to add the DELIMITER change from and to ;
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Author Closing Comment

by:Robert Silver
ID: 36477914
For the record what does DELIMITER //    {CODE} //   do?
0
 
LVL 2

Author Comment

by:Robert Silver
ID: 36478051
I beleieve this is due to a semicolon confusing things so by making // the delimiter
we open and close the code in  // marks.
I believe this is explained in the Section 17.1 of the pdf file: mysql-refman-5.5-en.pdf file
reference manual found at
 http://dev.mysql.com/doc/

Would that be correct?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36478122
Yes. Since the semicolon is the delimiter and as such is likely to be in your code of the function, you have to change the delimiter temporarily, then change it back when you are done.

-- ; used here since we have not changed delimiter yet
USE mysql;

DELIMITER //

-- // used here since we already changed delimiter
DROP FUNCTION IF EXISTS lup_t1 //

CREATE FUNCTION lup_t1(sid int(12) ) RETURNS text DETERMINISTIC
BEGIN
        DECLARE a1 text;
        SELECT  abstract into a1 from notestbl where Id=sid;
        RETURN a1;
END
//
DELIMITER ;
0
 
LVL 22

Expert Comment

by:pivar
ID: 36478338
You have to show where the procedure ends, at the same time you have to show where each statement ends. So to not confuse the parser, you need to have different delimiters.
delimiter // changes the delimiter showing where the procedure ends, while the delimiter for statements stays as ;

If you have an one line procedure you don't need to change delimiter:

CREATE FUNCTION hello (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC
RETURN CONCAT('Hello, ',s,'!');

0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…

664 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