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

老子叫甜甜 提交于 2019-12-31 03:57:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!