@@CURSOR_ROWS (Transact-SQL)@@CURSOR_ROWS (Transact-SQL)

适用对象:是SQL Server 是Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库APPLIES TO: yesSQL Server yesAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

它返回在连接上打开的上一个游标中当前拥有的限定行的数目。This returns the number of qualifying rows currently in the last cursor opened on the connection. 为了提高性能,SQL ServerSQL Server 可异步填充大型键集和静态游标。To improve performance, SQL ServerSQL Server can populate large keyset and static cursors asynchronously. 可调用 @@CURSOR_ROWS 以确定当 @@CURSOR_ROWS 被调用时检索了游标符合条件的行数。@@CURSOR_ROWS can be called to determine that the number of the rows that qualify for a cursor are retrieved at the time of the @@CURSOR_ROWS call.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

@@CURSOR_ROWS  

返回类型Return types

integerinteger

返回值Return Value

返回值Return value 描述Description
-m -m 游标被异步填充。The cursor populates asynchronously. 返回的值 (-m) 是键集中当前的行数mThe value returned (-m) is the number of rows currently in the keyset.
-1-1 游标为动态游标。The cursor is dynamic. 因为动态游标可反映所有更改,所以游标符合条件的行数不断变化。Because dynamic cursors reflect all changes, the number of rows that qualify for the cursor constantly changes. 游标不一定检索所有符合条件的行。The cursor does not necessarily retrieve all qualified rows.
00 没有已打开的游标,对于上一个打开的游标没有符合条件的行,或上一个打开的游标已被关闭或被释放。No cursors have been opened, no rows qualified for the last opened cursor, or the last-opened cursor is closed or deallocated.
nn 游标已完全填充。The cursor is fully populated. 返回值 (n) 是游标中的总行数 。The value returned (n) is the total number of rows in the cursor.

RemarksRemarks

如果异步打开最后一个游标,@@CURSOR_ROWS 返回负数。@@CURSOR_ROWS returns a negative number if the last cursor opened asynchronously. 如果 sp_configure cursor threshold 的值超过 0,且游标结果集中的行数大于游标阈值,则异步打开键集驱动程序或静态游标。Keyset-driver or static cursors open asynchronously if the value for sp_configure cursor threshold exceeds 0, and the number of rows in the cursor result set exceeds the cursor threshold.

示例Examples

此示例首先声明了一个游标,然后使用 SELECT 显示 @@CURSOR_ROWS 的值。This example first declares a cursor, and then uses SELECT to display the value of @@CURSOR_ROWS. 在游标打开前,该设置的值为 0,之后其值为 -1,后者表示游标键集被异步填充。The setting has a value of 0 before the cursor opens and then has a value of -1, to indicate that the cursor keyset populates asynchronously.

USE AdventureWorks2012;  
GO  
SELECT @@CURSOR_ROWS;  
DECLARE Name_Cursor CURSOR FOR  
SELECT LastName ,@@CURSOR_ROWS FROM Person.Person;  
OPEN Name_Cursor;  
FETCH NEXT FROM Name_Cursor;  
SELECT @@CURSOR_ROWS;  
CLOSE Name_Cursor;  
DEALLOCATE Name_Cursor;  
GO             

下面是结果集。Here are the result sets.

-----------
0  
LastName
---------------
Sanchez
-----------
-1

另请参阅See also

游标函数 (Transact-SQL)Cursor Functions (Transact-SQL)
OPEN (Transact-SQL)OPEN (Transact-SQL)