S
S
sisharpacc2014-10-22 12:18:09
Oracle
sisharpacc, 2014-10-22 12:18:09

Oracle: how to populate an attribute with random IDs from another table?

(select * from (SELECT OWNER_ID FROM NEW_OWNER 
ORDER BY dbms_random.value)
where rownum = 1);

Works fast. But it's been so unrealistically long:
update new_hill set owner_id = (select * from (SELECT OWNER_ID FROM NEW_OWNER 
ORDER BY dbms_random.value)
where rownum = 1) where rownum <= 1;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fessvmk, 2014-10-22
@fessvmk

update new_hill
   set owner_id =  (select owner_id from new_owner sample(0.001) where rownum = 1)
 where rownum <= 1;

You have a fullscan of the NEW_OWNER table, and also the calculation of dbms_random.value for each row. Better use sample_clause: "The sample_clause lets you instruct the database to select from a random sample of data from the table, rather than from the entire table"
docs.oracle.com/cd/E11882_01/server.112/e17118/sta.. .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question