问题
I am trying to make a procdure in mysql that returns me an array with the result, I used to do with the oracle ref cursor, but in mysql do not know how to proceed, I have to pass parameters too...
Anyone know how I can do, or have an example to show me? Thank you very much...
回答1:
There is no analog of REF CURSOR in MySQL. Stored procedures and functions allow to pass and return only scalar datata types, see the reference here - CREATE PROCEDURE and CREATE FUNCTION Syntax.
MySQL cannot operate with arrays. A workaround is to use a table (or TEMPORARY TABLE).
Also - take advantage of visual object editors and stored procedure debugger in dbForge Studio for MySQL.
回答2:
MySQL doesn't have a refcursor like Oracle. If you are planning to write a stored procedure that returns multiple rows/result set in MySQL just do
DROP procedure IF EXISTS `sample`;
DELIMITER $$
CREATE PROCEDURE `sample`(p_rank IN INT)
BEGIN
select * from MyTable where id=p_rank;
END$$
DELIMITER ;
and call sample();
. It will return a result set which you can use.
来源:https://stackoverflow.com/questions/7155790/what-is-the-equivalent-of-oracle-s-ref-cursor-in-mysql