Name
CLOSE CURSOR Statement
The CLOSE CURSOR statement closes a server-side cursor previously created with a DECLARE CURSOR statement.
Platform | Command |
MySQL | Supported |
Oracle | Supported |
PostgreSQL | Supported |
SQL Server | Supported, with variations |
SQL2003 Syntax
CLOSE cursor_name
Keywords
cursor_name
Names a cursor previously created with the DECLARE CURSOR statement.
Rules at a Glance
The CLOSE statement closes a cursor and destroys the cursor result set. All the database platforms release any locks that were held by the cursor, though this is not specified in the ANSI standard. For example:
CLOSE author_names_cursor;
Programming Tips and Gotchas
You can also close a cursor implicitly using a COMMIT statement or, for cursors defined with WITH HOLD, using a ROLLBACK statement.
MySQL
MySQL supports the ANSI-standard form of the statement.
Oracle
Oracle supports the ANSI-standard form of the statement.
PostgreSQL
PostgreSQL supports the ANSI-standard syntax. PostgreSQL issues an implicit CLOSE statement for every open cursor when a transaction is ended with a COMMIT or ROLLBACK statement.
SQL Server
Microsoft SQL Server supports the ANSI-standard syntax, and an additional GLOBAL keyword:
CLOSE [GLOBAL] cursor_name
where:
- GLOBAL
Identifies the previously defined cursor as a global cursor.
In the ANSI-standard behavior, closing a cursor destroys the cursor result set. Locking is a physical feature of each database platform and thus not a part of the ANSI SQL definition. However, all the database platforms covered here drop ...
Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.