开发者

What is the equivalent of Oracle’s REF CURSOR in MySQL?

开发者 https://www.devze.com 2023-03-30 03:38 出处:网络
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 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 para开发者_开发技巧meters too...

Anyone know how I can do, or have an example to show me? Thank you very much...


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消