0

PostgreSQL allows you to define a function that returns a table. Does MySQL provide a similar feature? My research suggests not, but I'd be grateful if someone could show me otherwise.

Essentially, I want to add a "running-total" column to a rowset, and this is one of the options I'm investigating.

1 Answer 1

1

You can not return a table using MySQL function, but you can using a stored procedure, I got something like this:

 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

And for more information please refer to this link

Sign up to request clarification or add additional context in comments.

1 Comment

That 's what I thought. It's not the answer I was hoping for, but it is what I expected, with a little sample code thrown in as a bonus.

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.