Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Not allowed to return a result set from a function

Posted on 2008-09-29
3
Medium Priority
?
1,138 Views
Last Modified: 2012-05-05
Hi we are migrating a procedure from mssql to mysql.
if i executed the following function on mysql iam getting "Not allowed to return a result set from a function" error.
CREATE FUNCTION TABLE_COL_LIST(xtable VARCHAR(100),includeclientid varchar(1)) RETURNS varchar(4000)
BEGIN
DECLARE colname VARCHAR(300);declare collist VARCHAR(4000);declare foundclientid VARCHAR(200);
declare cnt int default 0;
declare fetch_status int default 0;
  DECLARE table_cur CURSOR FOR
SELECT COLUMN_NAME FROM information_schema.COLUMNS C where TABLE_SCHEMA=(select database()) and table_name=xtable;
select fetch_status;
  SET @collist = '';
  IF (includeclientid IS NULL) then
  BEGIN
     SET includeclientid = 'F';
  END;
  end if;
  begin
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET fetch_status =-1;
   OPEN table_cur;
  FETCH FROM table_cur INTO colname;
     WHILE (fetch_status=0) do
  BEGIN
      IF NOT(colname = 'CLIENT_ID') then
begin
      IF (@collist = '') then
           SET @collist = colname;
      ELSE
        set  @collist=concat(@collist ,',',colname);
        END if;
end;
    ELSE IF (includeclientid = 'T') then
      SET foundclientid = colname;
      end if;
       END if;
     FETCH NEXT FROM table_cur INTO colname;
end;
  end while;
  CLOSE table_cur;
  end;
  IF NOT(foundclientid IS NULL) AND (includeclientid = 'T') then
set  @collist=concat(foundclientid,',',@collist);
END if;
  RETURN @collist;
END
can any one help me why iam getting this error and how do i solve it;
Regards,
vijji
0
Comment
Question by:vijji_lakshmi
3 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 2000 total points
ID: 22602624
Just underneath your cursor declaration, you have:

select fetch_status;

That would return a result set.
0

Featured Post

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.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
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

972 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