Solved

Not allowed to return a result set from a function

Posted on 2008-09-29
3
1,125 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 50

Accepted Solution

by:
Steve Bink earned 500 total points
Comment Utility
Just underneath your cursor declaration, you have:

select fetch_status;

That would return a result set.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now