如何从存储过程的结果集中获取“返回"的行数 [英] How can I get the number of rows 'returned' from a result set of a stored procedure

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

问题描述

是否有一种方法可以从存储过程中返回"行数? 我知道结果集并没有真正返回,因此我无法从中选择或依靠它. 我尝试使用out参数,但没有成功..

Is there a way to get the number of rows 'returned' from a stored procedure? I know the result set is not really returned so I can't select from it or count on it. I tried to use an out parameter but with no success..

基本上,我在存储过程中有一些逻辑可以找到一些表行.我在C#应用程序中使用它.在另一个地方,我需要完全相同的逻辑,但只需要计数,这样我就可以在SQL语句中使用.

Basically I have some logic in the stored procedure that finds some table lines. I use it in my C# app. in another place I need the exact same logic but only the count so I will be able to use in an SQL statement.

我可以将其带到C#并在那里计数,但我不喜欢. 我还可以创建一个存储函数,该函数复制逻辑但返回COUNT,但我不想复制,因此我不会对其进行两次维护.

I could bring it to the C# and count there but I prefer not. I could also create a stored function that duplicate the logic but returns COUNT but I prefer not to duplicate so I don't maintain it twice..

推荐答案

尝试一下 found_rows函数

Try This found_rows function

http://dev.mysql. com/doc/refman/5.0/en/information-functions.html#function_found-rows

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

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