Solved

Not allowed to return a result set from a function

Posted on 2008-09-29
3
1,129 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
ID: 22602624
Just underneath your cursor declaration, you have:

select fetch_status;

That would return a result set.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

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