从 MYSQL 存储过程返回多个结果集 [英] Return Multiple Result Sets from MYSQL Stored Procedure

查看:106
本文介绍了从 MYSQL 存储过程返回多个结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 MYSQL 存储过程返回多个结果集?

How do you return multiple result sets from a MYSQL Stored Procedure?

这是我的测试存储过程:

This is my test stored proc:

DELIMITER $$

CREATE DEFINER=`hlamAdmin`@`%` PROCEDURE `test`()
BEGIN
   SELECT *
   FROM hlam.member;

   SELECT * 
   FROM hlam.security;

END

现在当我调用它时:

Call test()

我只收到一个结果集.我如何接收两者?我习惯了 MSSQL,如果这是一个简单的问题,我深表歉意.

I only receive one resultset. How do I receive both? I am used to MSSQL I apologize if this is an easy question.

推荐答案

您可以尝试 JOIN 它们(将它们链接在一起)或使用 UNION(将两个选择合二为一);

You could try to either JOIN them (Linking them together) or use UNION (Combine two selects in one);

http://dev.mysql.com/doc/refman/5.0/en/join.html

select a.col1, b.col1
from table1 a
inner join table2 b on a.id = b.id;

http://dev.mysql.com/doc/refman/5.0/en/union.html

select name as col1, surname as col2 from table1
union
select location as col1, desc as col2 from table2;

约翰

这篇关于从 MYSQL 存储过程返回多个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆