如何获得受存储过程影响的记录数? [英] How can I get the number of records affected by a stored procedure?

查看:64
本文介绍了如何获得受存储过程影响的记录数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于直接针对数据库执行的INSERTUPDATEDELETE SQL语句,大多数数据库提供程序都返回受影响的行数.对于存储过程,受影响的记录数始终为-1.

For INSERT, UPDATE and DELETE SQL statements executed directly against the database, most database providers return the count of rows affected. For stored procedures, the number of records affected is always -1.

我们如何获取受存储过程影响的记录数?

How do we get the number of records affected by a stored procedure?

推荐答案

为存储过程注册一个out参数,如果使用SQL Server,则基于@@ROWCOUNT设置值.如果使用的是Oracle,请使用SQL%ROWCOUNT.

Register an out parameter for the stored procedure, and set the value based on @@ROWCOUNT if using SQL Server. Use SQL%ROWCOUNT if you are using Oracle.

请注意,如果您有多个INSERT/UPDATE/DELETE,则需要一个变量来存储每个操作的@@ROWCOUNT结果.

Mind that if you have multiple INSERT/UPDATE/DELETE, you'll need a variable to store the result from @@ROWCOUNT for each operation.

这篇关于如何获得受存储过程影响的记录数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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