sql
what is a cursor?why cursor is needed?it's uses?plz explain me all about cursor.and also give example for it.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Akkiraju IvaturiPosted Aug 31, 2012, 7:00 PM
A cursor can only work on one row at a time. You cannot do something like a batch updates or insertions using cursors.
To use a cursor, we need to follow the steps:
1. Declare a cursor that defines a resultset
2. Open the cursor variable to establish the resultset.
3. Fetch the data into local variables as needed from cursor, one row at a time.
4. Perform operations on each row.
5. Close the cursor when the operation is completed i.e., all row have been completed.
The following statements are needed to define cursors:
DECLARE CURSOR
OPEN
FETCH
CLOSE
DEALLOCATE
Example of the cursor:
Let me know if you have any questions.