Skip to content

SCROLL

DECLARE cursor_scroll CURSOR SCROLL FOR SELECT * FROM employees;
FETCH NEXT FROM cursor_scroll;
FETCH PRIOR FROM cursor_scroll;

For FETCH NEXT command:

id | name | department
---+---------+------------
2 | Peter | HR

For FETCH PRIOR command:

id | name | department
---+---------+------------
1 | Alice | Sales

In the example code, a SCROLL cursor named “cursor_scroll” is declared. The SQL SELECT statement retrieves all records from the “employees” table. Firstly, the FETCH NEXT command is used to retrieve the next row from the cursor which in result, returns the second row from the “employees” table. Then, the FETCH PRIOR command is used to retrieve the prior row from the cursor, which returns back to the first row of the “employees” table.