Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting the number of rows returned by stored procedure

Tags:

How do I count the number of rows a stored procedure would return the fastest way. Stored procedure returns rows around 100K to 1M records.

like image 702
quarks Avatar asked Jan 23 '13 07:01

quarks


People also ask

How do I count the number of rows returned?

To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.

How can I get the number of records affected by a stored procedure?

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. Show activity on this post. @@RowCount will give you the number of records affected by a SQL Statement.

How can use stored procedure Rowcount in SQL Server?

SQL Server @@ROWCOUNT with Try Catch@@ROWCOUNT returns the affected rows from any statement, even if it's not DML or a SELECT query.

How do I count rows in SQL?

Use the COUNT aggregate function to count the number of rows in a table. This function takes the name of the column as its argument (e.g., id ) and returns the number of rows for this particular column in the table (e.g., 5).


2 Answers

You can define output variable:

create procedure x
    (@p1 int output)
as
    select @p1 = count(*) 
    from Table
like image 37
H. Aghassi Avatar answered Sep 18 '22 18:09

H. Aghassi


Select @@rowcount:

SELECT @@ROWCOUNT;

After executing the stored procedure.

like image 146
Mahmoud Gamal Avatar answered Sep 22 '22 18:09

Mahmoud Gamal