MySQL 过程多个结果
基本思想是,当我调用过程时,我想要获取一组数据而不仅仅是一个值(通过将 results
设置为 INT
并选择 COUNT( id)
例如)。 我想知道如何更改此过程以获得多个值......
DELIMITER //
CREATE PROCEDURE getnames(IN id_in INT,OUT results ???)
BEGIN
set results=(select name from people where id>id_in);
END //
DELIMITER ;
The basic ideea is that when I call a procedure I want to get a set of data not just one value (by setting results
to be INT
and selection COUNT(id)
for instance).
I would like to know how to change this procedure to get multiple values...
DELIMITER //
CREATE PROCEDURE getnames(IN id_in INT,OUT results ???)
BEGIN
set results=(select name from people where id>id_in);
END //
DELIMITER ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非我误解了,否则您应该能够将您的过程更改为以下内容
这将仅返回选择查询的结果,在本例中是名称集。
Unless I've misunderstood then you should simply be able to alter your procedure to the following
This will simply return the results of the select query, in this case the set of names.
这里的问题是MySQL只允许存储过程中的表列数据类型。遗憾的是,这不包括任何类型的数组、列表或集合类型。
类似的问题有
返回结果的另一种替代方法是将结果存储在“结果表”中,调用过程,然后从调用代码引用“结果表”中的结果。
The problem here is that MySQL only allows table column data types in stored procedures. Sadly this does not include any kind of array, list or collection type.
A similar question has been asked before. Have a read of the answers - they might help you. One of them includes passing a comma separated list out in a large
VARCHAR
data type.Another alternative to returning the results is to store the results in a 'results table', call the procedure and then reference the results in the 'results table' from the calling code.
MySQL中的参数不能是对象或表。如果您想返回多个值,请尝试填充临时表或仅在过程中运行 SELECT 语句并读取应用程序中的数据集。
The parameters in MySQL cannot be objects or tables. If you want to return multiple values, then try to fill temporary table or just run SELECT statement within the procedure and read dataset in the application.