The table shows the syntax for using cursors.
Operation | Oracle | Microsoft SQL Server |
---|---|---|
Declaring a cursor | CURSOR cursor_name [(cursor_parameter(s))] IS select_statement; |
DECLARE cursor_name CURSOR [LOCAL | GLOBAL] [FORWARD_ONLY | SCROLL] [STATIC | KEYSET | DYNAMIC | FAST_FORWARD] [READ_ONLY | SCROLL_LOCKS | OPTIMISTIC] [TYPE_WARNING] FOR select_statement [FOR UPDATE [OF column_name [,…n]]] |
Opening a cursor | OPEN cursor_name [(cursor_parameter(s))]; | OPEN cursor_name |
Fetching from a cursor | FETCH cursor_name INTO variable(s) | FETCH [[NEXT | PRIOR | FIRST | LAST | ABSOLUTE {n | @nvar} | RELATIVE {n | @nvar}] FROM] cursor_name [INTO @variable(s)] |
Update fetched row | UPDATE table_name SET statement(s)… WHERE CURRENT OF cursor_name; |
UPDATE table_name SET statement(s)… WHERE CURRENT OF cursor_name |
Delete fetched row | DELETE FROM table_name WHERE CURRENT OF cursor_name; |
DELETE FROM table_name WHERE CURRENT OF cursor_name |
Closing cursor | CLOSE cursor_name; | CLOSE cursor_name |
Remove cursor data structures | N/A | DEALLOCATE cursor_name |