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?
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.
Mind that if you have multiple INSERT/UPDATE/DELETE
, you'll need a variable to store the result from @@ROWCOUNT
for each operation.