13

I am using MySQL. I want to return the table using MySQL function. In SQL its working fine but not in MySQL. I attach my partial code

 DELIMITER $$

    CREATE FUNCTION myFunction() RETURNS @tmptable TABLE (item varchar(20))
    BEGIN  

        insert  into @tmptable(item) values('raja')     


        return
     END; $$
2
  • 2
    In MySQL, a function cannot return a table. You would have to use a stored procedure for that. Commented Nov 6, 2012 at 13:11
  • 5
    What do you mean with "In SQL it's working fine?". You are using SQL.... Commented Nov 6, 2012 at 13:28

1 Answer 1

9

Using functions you can not return a table.

However you can use stored procedure to return the table.

 DELIMITER $$

 CREATE DEFINER=`root`@`%` PROCEDURE `sp_Name`(OUT po_ErrMessage   VARCHAR(200))
 BEGIN
 DECLARE EXIT HANDLER FOR SQLEXCEPTION
 BEGIN
SET po_ErrMessage = 'Error in procedure sp_Name';
 END;

 SELECT * FROM table_name;
END
Sign up to request clarification or add additional context in comments.

2 Comments

Ya its working fine in procedure. Is there any way to return more than one row using MySQL function. If Possible means give example
You can check this:- stackoverflow.com/questions/10850731/… It will definitely help!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.