如何使用存储过程返回多行 [英] How to return multiple rows using Stored Procedure
本文介绍了如何使用存储过程返回多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是存储过程的新手.我写了一个查询来获取多行.但我收到像
I am new to Stored Procedure. I have written a query to get multiple rows. But I am getting error like
错误代码:1172.结果由多行组成.
Error Code: 1172. Result consisted of more than one row.
我应该使用 CURSOR 类型吗?
Should I use CURSOR type?
这里是我的查询和表结构.
Here my query and table structure.
我的表结构是:
+---+------+------+---------+
|id | name | class| section |
+---+------+------+---------+
|1 |abc |5 | A |
|2 |cdef |5 | B |
|3 |hikl |5 | A |
|4 |xyz |5 | A |
+---+------+------+---------+
我的存储过程查询是
CREATE DEFINER=`root`@`localhost` PROCEDURE `mulitiOut`(out namee VARCHAR(50))
BEGIN
select name into @namee from mytable where section = A;
END
如何返回与 A 部分相关的所有名称.
How can I return all the name related to section A.
推荐答案
您可以直接从过程返回结果集:
You can return a result set directly from a procedure:
CREATE DEFINER=`root`@`localhost` PROCEDURE `mulitiOut`()
BEGIN
SELECT name FROM mytable WHERE section = A;
END
这篇关于如何使用存储过程返回多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文