1 -- zhxia
2 DECLARE @ username VARCHAR (20), @ flag BIT, @ ncount int
3 DECLARE mycursor cursor for -- DECLARE the CURSOR
4 SELECT user_name FROM RBAC_User
5 OPEN mycursor -- OPEN the cursor
6 SET @ flag = 0
7 SET @ ncount = 0
8 WHILE (@ flag = 0)
9 BEGIN
10 SET @ ncount = @ ncount + 1
11 FETCH mycursor INTO @ username -- cyclically read cursor
12 IF (@ FETCH_STATUS = 0)
13 UPDATE RBAC_User SET User_PassWord = @ ncount WHERE User_Name = @ username
14 ELSE
15 SET @ flag = 1
16 END
17 CLOSE mycursor -- CLOSE the cursor
18 DEALLOCATE mycursor -- release resources
19
20 @ FETCH_STATUS
21. Return the status of the last cursor executed by the FETCH statement, rather than the status of any currently opened cursor.
22 @ FETCH_STATUS = 0 success
23 @ FETCH_STATUS =-1 The FETCH statement fails or this row is not in the result set.
24 @ FETCH_STATUS =-2 The extracted row does not exist.
25 @ FETCH_STATUS = 100 is in the last row