In this page you can learn how to declare an cursor by reading the syntax and the example.
Declare cursor Syntax:
DECLARE cursor_name CURSOR [ LOCAL | GLOBAL ]
[ FORWARD_ONLY | SCROLL ]
[ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
[ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]
[ TYPE_WARNING ]
FOR select_query_statement
[ FOR UPDATE [ OF column_name [ ,...n ] ] ] ;
Declare simple cursor example:
DECLARE product_cursor CURSOR
FOR SELECT * FROM model.dbo.products;
OPEN product_cursor
FETCH NEXT FROM product_cursor;
product_id | product_name | product_dsp | product_type |
---|---|---|---|
1 | pro_1 | product_1 | AAA |