A cursor is a special kind of loop for traversing through an SQL resultset one row at a time.
You are not attempting to update multiple columns (which are called fields) with a cursor.
You are attempting to process through the cursor records (which are called features or rows) more than once with a single cursor.
Update Cursor (fc, fields) as cursor: for row in cursor: example2 = (row) if example == None: row = None cursor.update Row(row) else: variable = dict1[example2] row = variable cursor.update Row(row) for row2 in cursor: example2 = (row1) if example2 == None: row1 = None cursor.update Row(row) else: test = somedict[example2] row1 = test cursor.update Row(row) del row The above code executes but does not update the second column (the first one is updated properly).
The update cursor updates each column based on a dictionary I have created separately.
CREATE TABLE My Table (Id INT Identity, Col2 int, Col3 int) INSERT INTO My Table (Col2, Col3) VALUES (2,1), (3,0), (4,0),(5,0),(6,0) SELECT * from My Table WHILE (SELECT COUNT(*) FROM My Table WHERE Col3=0) @Hemant Sisodia you can replace the conditional in the WHILE to an EXISTS which should be quicker as it short circuits. If you need to be to REALLY fast you can use your PK to loop through those records too, i.e.
only work on PK values between 1-10,000 for first loop, then do the next 10k etc.
A handler_action constant may be used to indicate what action the handler takes after execution of the handler statement.
The table has no PK or Unique Index because of Application reasons.
The DECLARE statement declares a cursor and associates it with a SELECT statement that retrieves the rows to be traversed by the cursor.
Cursor declarations must appear after variable and condition declarations but before handler declarations.
What I would like to do is to update the field that causes the record to be duplicate by adding a consequitive sequence to the end of the field: i.e : say I have the following 6 records where the most left field is the duplicate field: a12,123,ddd,fff a12,345,ggg,hhh a12,567,fff,lll b11,eee,ttt,yyy b11,rrr,hhh,jjj c11,ggg,uuu,ttt Now I must fetch the duplicates : (in this case a12 and b11 only ) and update the fields so the new records will be: a12_1,123,ddd,fff a12_2,345,ggg,hhh a12_3,567,fff,lll b11_1,eee,ttt,yyy b11_2,rrr,hhh,jjj c11,ggg,uuu,ttt Can any one please help and might have an idea how to do this (sql or plsql) ?