Monday 15 February 2010

Oracle SQL update every nth row -


To do some testing on a new table field, I want to duplicate some values ​​on existing records in my test database . I want to assign a value for every 8th record in the table. I can easily select every 8th record using this syntax: choose

 from  to select (rownum) , Jeff to jeffs_field_to_update) where mod (rn, 8) = 0;   

However, I am quite new in SQL, and I can not be able to convert it to an updated statement. I get a lot of answers about the selection of number records, but I have already found it. Any help would be appreciated.

You need to include any key in the UPDATE statement in the table. For example, if you have a unique ID column, the update statement will look like this:

  update Jeff set jeffs_field_to_update = value where id (choose ID (choose rownum rn, jeff.id From Jeff) where Mod (RN, 8) = 0)    

No comments:

Post a Comment