Recently I have seen a headache with cursor problems. Refresh the cursor.
1 declare @ id varchar (50 );
2 declare @ Title varchar (50 );
3 declare @ Director varchar (50 );
4 declare @ DateReleased varchar (50 );
5
6 declare mycursor cursor for -- defines a cursor
7 select * from movies -- The cyclable object of the cursor
8 open mycursor -- open the cursor
9 fetch next from mycursor into @ id, @ Title, @ Director, @ DateReleased -- move the cursor to the next data (the first one), get the data @ id, @ Title, @ Director, @ DateReleased (the number must be the same)
10 while (@ FETCH_STATUS = 0) -- determines whether data is obtained successfully.
11 /*
12 @ FETCH_STATUS = 0 The FETCH statement is successful.
13 @ FETCH_STATUS =-1 The FETCH statement fails or this row is not in the result set
14 @ FETCH_STATUS =-2 The extracted row does not exist.
15 */
16
17 begin
18
19 print (@ Title) -- operation on the cursor
20 fetch next from mycursor into @ id, @ Title, @ Director, @ DateReleased -- move the cursor down one line
21 end
22 close mycursor -- close the cursor
23 deallocate mycursor -- delete a cursor