You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specifies a constant indicating that the cursor source is a local cursor name.
41
-
42
-
'*cursor_name*'
43
-
The name of the cursor. A cursor name must conform to the [database identifier rules](../../relational-databases/databases/database-identifiers.md).
44
-
45
-
'global'
46
-
Specifies a constant indicating that the source of the cursor is a global cursor name.
47
-
48
-
'variable'
41
+
42
+
#### 'local'
43
+
44
+
Specifies a constant indicating that the cursor source is a [local cursor](../language-elements/declare-cursor-transact-sql.md#local).
45
+
46
+
-**'*cursor_name*'**
47
+
48
+
The name of the cursor. A cursor name must conform to the [database identifier rules](../../relational-databases/databases/database-identifiers.md).
49
+
50
+
#### 'global'
51
+
52
+
Specifies a constant indicating that the source of the cursor is a [global cursor](../language-elements/declare-cursor-transact-sql.md#global).
53
+
54
+
#### 'variable'
55
+
49
56
Specifies a constant indicating that the source of the cursor is a local variable.
50
-
51
-
'*cursor_variable*'
52
-
The name of the cursor variable. A cursor variable must be defined using the **cursor** data type.
53
-
57
+
58
+
-**'*cursor_variable*'**
59
+
60
+
The name of the cursor variable. A cursor variable must be defined using the **cursor** data type.
61
+
54
62
## Return types
63
+
55
64
**smallint**
56
-
57
-
|Return value|Cursor name|Cursor variable|
58
-
|---|---|---|
59
-
|1|The cursor result set has at least one row.<br /><br /> For insensitive and keyset cursors, the result set has at least one row.<br /><br /> For dynamic cursors, the result set can have zero, one, or more rows.|The cursor allocated to this variable is open.<br /><br /> For insensitive and keyset cursors, the result set has at least one row.<br /><br /> For dynamic cursors, the result set can have zero, one, or more rows.|
60
-
|0|The cursor result set is empty.*|The cursor allocated to this variable is open, but the result set is definitely empty.*|
61
-
|-1|The cursor is closed.|The cursor allocated to this variable is closed.|
62
-
|-2|Not applicable.|Has one of these possibilities:<br /><br /> The previously called procedure did not assign a cursor to this OUTPUT variable.<br /><br /> The previously assigned procedure assigned a cursor to this OUTPUT variable, but the cursor was in a closed state when the procedure completed. Therefore, the cursor is deallocated, and not returned to the calling procedure.<br /><br /> No cursor is assigned to the declared cursor variable.|
63
-
|-3|A cursor with the specified name does not exist.|A cursor variable with the specified name does not exist, or if one exists, no cursor is yet allocated to it.|
64
-
65
-
*Dynamic cursors never return this result.
66
-
67
-
## Examples
65
+
66
+
| Return value | Cursor name | Cursor variable |
67
+
| --- | --- | --- |
68
+
|`1`| The cursor result set has at least one row.<br /><br />For insensitive and keyset cursors, the result set has at least one row.<br /><br />For dynamic cursors, the result set can have zero, one, or more rows. | The cursor allocated to this variable is open.<br /><br />For insensitive and keyset cursors, the result set has at least one row.<br /><br />For dynamic cursors, the result set can have zero, one, or more rows. |
69
+
|`0`| The cursor result set is empty. <sup>1</sup> | The cursor allocated to this variable is open, but the result set is definitely empty.*|
70
+
|`-1`| The cursor is closed. | The cursor allocated to this variable is closed. |
71
+
|`-2`| Not applicable. | Has one of these possibilities:<br /><br />The previously called procedure didn't assign a cursor to this `OUTPUT` variable.<br /><br />The previously assigned procedure assigned a cursor to this `OUTPUT` variable, but the cursor was in a closed state when the procedure completed. Therefore, the cursor is deallocated, and not returned to the calling procedure.<br /><br />No cursor is assigned to the declared cursor variable. |
72
+
|`-3`| A cursor with the specified name doesn't exist. | A cursor variable with the specified name doesn't exist, or if one exists, no cursor is yet allocated to it. |
73
+
74
+
<sup>1</sup> Dynamic cursors never return this result.
75
+
76
+
## Examples
77
+
68
78
This example uses the `CURSOR_STATUS` function to show the status of a cursor, after its declaration, after it opens, and after it closes.
69
-
79
+
70
80
```sql
71
-
CREATE TABLE #TMP
72
-
(
73
-
ii INT
74
-
)
75
-
GO
76
-
77
-
INSERT INTO#TMP(ii) VALUES(1)
78
-
INSERT INTO#TMP(ii) VALUES(2)
79
-
INSERT INTO#TMP(ii) VALUES(3)
80
-
81
-
GO
82
-
83
-
--Create a cursor.
84
-
DECLARE cur CURSOR
85
-
FOR SELECT*FROM#TMP
86
-
87
-
--Display the status of the cursor before and after opening
0 commit comments