CLOSE is a cursor-control statement defined in the SQL standard. A cursor must first be declared with DECLARE and opened with OPEN (or implicitly opened, depending on the dialect). When you issue CLOSE cursor_name, the database:- Releases any memory and locks tied to the cursor’s result set.- Invalidates the cursor position so further FETCH, MOVE, or UPDATE WHERE CURRENT commands fail.- Keeps the cursor definition in session scope, allowing an optional subsequent OPEN of the same cursor within the same transaction or connection.CLOSE does not commit or roll back the surrounding transaction. In some systems (e.g., SQL Server), you may additionally issue DEALLOCATE to remove the cursor definition entirely. Failing to close cursors can lead to excessive memory usage, open transactions, or lock contention.
SQL-92
The cursor stays active for the session or transaction, consuming memory and potentially holding locks. Over time this can degrade performance and exhaust available cursors.
Yes. CLOSE only works on cursors that are currently open. Declaring a cursor does not automatically open it in all dialects.
No. FETCH, MOVE, or positioned UPDATE statements referencing that cursor will raise an error like "cursor is not open".
Not directly. CLOSE affects only cursor state. Use COMMIT or ROLLBACK to terminate or undo the transaction enclosing the cursor work.