Inspectopedia
 
2024.3

Illegal cursor state

Warning
New
Last modified: 03 December 2024

Reports illegal cursor states inside SQL routines.

  • A routine has CLOSE or FETCH statements but a cursor might be closed.

  • A routine has the OPEN statement but a cursor might be opened.

Example (Microsoft SQL Server):

According to CLOSE (Transact-SQL) at docs.microsoft.com, CLOSE must be issued on an open cursor, and CLOSE is not allowed on cursors that have only been declared or are already closed. So, we need to open the cursor to fix the warning.