RELATIVE is a scroll-orientation keyword used inside a FETCH statement on a scrollable cursor. Instead of moving the cursor to a fixed position (ABSOLUTE) or reading sequentially (NEXT, PRIOR), RELATIVE shifts the cursor by an offset from its present row. A positive offset moves forward, a negative offset moves backward, and zero refetches the current row. If the requested offset positions the cursor before the first or after the last row, the fetch returns no data and the cursor is left positioned before first or after last respectively. RELATIVE may only be used on scrollable (not forward-only) cursors, and performance can degrade on large result sets because the database must count rows to reach the target. The keyword is part of the SQL-92 standard and is implemented in several major systems, though syntax details vary.
offset_integer
(INTEGER) - Number of rows to move relative to the current position (positive, negative, or 0)cursor_name
(identifier) - Name of an open scrollable cursorFETCH, CURSOR, ABSOLUTE, NEXT, PRIOR, FIRST, LAST, SCROLL
SQL-92
PostgreSQL, SQL Server, DB2, and SAP HANA implement RELATIVE in standard FETCH syntax. MySQL and SQLite do not.
Yes. Large offsets can force the database engine to scan multiple rows to reach the target, which can be slower than sequential NEXT fetches.
Use `FETCH RELATIVE -1 FROM cursor_name;` on a scrollable cursor.
Use `FETCH ABSOLUTE 100 FROM cursor_name;` instead of RELATIVE for direct positioning.