How to Count Number of Rows into Cursor in SQL

In this article I am going to explain how to count number of rows into a cursor in SQL
  • 22080

Introduction

A cursor is a database object that points to a result set. We use cursor to fetch any specific row from result set. Most of time cursor is used by application programmer.

Implementation of cursor in SQL

  • We can implement cursor through standard database APIs.
  • We can implement cursor through Transact-SOL

SQL Statement used in cursor

  • DECLARE : It is used to define a new cursor.
  • OPEN : It is used to open a cursor
  • FETCH : It is used to retrieve a row from a cursor.
  • CLOSE : It is used to close a cursor.
  • DEALLOCATE : It is used to delete a cursor and releases all resources used by cursor.

@@CURSOR_ROWS System Function

@@CURSOR_ROWS System Function is used to find the number of rows in result set. @@CURSOR_ROWS System Function only works with static cursor. It doesn't works with dynamic cursor.

Statement that use @@FETCH_STATUS system function

Clipboard29.jpg

Statement that use @@cursor_rows system function 

Clipboard31.jpg


© 2020 DotNetHeaven. All rights reserved.