SCROLL is a cursor attribute defined in the SQL standard and implemented by several databases, notably PostgreSQL. When you declare a cursor with the SCROLL keyword, the database engine builds internal structures that allow the cursor to move both forward and backward through the result set. This enables FETCH statements such as PRIOR, ABSOLUTE n, or RELATIVE n. Without SCROLL, a cursor is typically forward-only, meaning you can FETCH NEXT repeatedly but cannot revisit earlier rows. Scrollable cursors are valuable for pagination, bi-directional navigation, and algorithms that must look ahead or behind in a result set. They do, however, consume more memory and may prevent certain optimizations because the engine must be able to reposition the cursor at will. Some databases allow SCROLL only on read-only or insensitive cursors, while others materialize the full result set in temp storage. Always benchmark if performance matters.
cursor_name
(identifier) - The name assigned to the cursorselect_statement
(SQL) - Any valid SELECT that produces the cursor's result setDECLARE CURSOR, FETCH, NO SCROLL, INSENSITIVE, FOR UPDATE
SQL-92 (as part of the ISO/IEC SQL standard)
SCROLL allows a cursor to move backward, jump to absolute positions, or fetch relative rows. NO SCROLL (or omitting SCROLL) restricts the cursor to forward-only FETCH NEXT operations.
In most databases SCROLL is allowed only on read-only or INSENSITIVE cursors. Attempting to update through a SCROLL cursor may raise an error or silently degrade to forward-only.
Consult your database documentation. PostgreSQL, SQL Server, and Db2 support it natively. MySQL and SQLite do not. You can also attempt DECLARE my_cur SCROLL CURSOR FOR SELECT 1; and see if it compiles.
Yes. Scrollable cursors often require the database to buffer the full result set or maintain extra metadata. Use SCROLL only when bidirectional navigation is necessary.