Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Update random rows in sql table

617078Mar 3 2008 — edited Oct 30 2008
Do not ask me why but I have to do it and I would greatly appreciate any help.

Let us say that I want to update column foo_column of a table foo. The selection criteria is foo_selection_criteria. So my sql to update would be something like:

update foo set foo_column='some value' where <foo_selection_criteria>

Foo_selection_criteria can be any logical expression based on the value of columns in table foo. For example foo_selection_criteria could be foo.columna != '1';

There are m rows in the table that meet the foo_selection_criteria. I want to update only randomly selected 1/n (eg., 0.5 , 083 etc) of these m rows.

I tried using dbms_random.value procedure to update my sql above so that it reads something like

update foo set foo_column='some value' where <foo_selection_criteria> and dbms_random.value <= 1/n;

However it seems that dbms_random is evaluated only once in the update sql above. Is there any way I can avoid that dbms_value is calculated once and stick in the sql above ? Or is someone aware of another way to randomly update a random fraction of m rows that meed an update selection criteria ?

I would be grateful for any help/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2008
Added on Mar 3 2008
6 comments
3,913 views