What is the equivalent of Oracle’s REF CURSOR in M

2019-03-06 11:17发布

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...

2条回答
Root(大扎)
2楼-- · 2019-03-06 11:29

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.

查看更多
趁早两清
3楼-- · 2019-03-06 11:33

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.

查看更多
登录 后发表回答