Hello All,
I have got answers table, there are two columns which belong to that table. This table consists 1 million rows. The answer column can be numeric or text.
create table answers(
answer_id number primary key,
answer varchar2(50)
);
My question is
I want to update 50 random rows to 100 which is equal to '0' (zero).
The below code works but I just wonder does it work correctly? I mean, I want to choose these rows randomly. However it is very hard to update random. Is this the best way? Do you have any suggestions?
update answers set answer = '100' where answer_id in(
with
get_ids as (select answer_id from answers where answer = '0' and rownum <= 50 order by dbms_random.value)
select answer_id from get_ids);
In addition, when I read threads relevant to random update, somebody recommends using rowid, do you think should I use rowid instead of answer_id? (answer_id is also unique value in my table) If I use rowid will it be faster?
Thanks for your help.