Difference between revisions of "Oracle/Shuffle data"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
The following statement | The following statement shuffles to content of columns (name and street): | ||
<source lang="oracle11"> | <source lang="oracle11"> | ||
-- shuffle the columns name and street (separately) | -- shuffle the columns name and street (separately) | ||
MERGE INTO address t1 | MERGE INTO address t1 | ||
| Line 12: | Line 9: | ||
nvl(lead(street) over (order by dbms_random.value(2,2)), | nvl(lead(street) over (order by dbms_random.value(2,2)), | ||
first_value(street) over (order by dbms_random.value(2,2))) street | first_value(street) over (order by dbms_random.value(2,2))) street | ||
FROM | FROM address) t2 | ||
ON (t1.address_id = t2.address_id) | ON (t1.address_id = t2.address_id) | ||
WHEN matched THEN | WHEN matched THEN | ||
UPDATE | UPDATE | ||
SET t1.name = t2.name, t1.street = t2.street; | SET t1.name = t2.name, t1.street = t2.street; | ||
</source> | </source> | ||
The individual random values are used so that both columns are shuffled separately (else they would stay together as a pair). | |||
Revision as of 12:39, 5 May 2011
The following statement shuffles to content of columns (name and street):
-- shuffle the columns name and street (separately)
MERGE INTO address t1
USING (SELECT address_id,
nvl(lead(name) over (order by dbms_random.value(1,1)),
first_value(name) over (order by dbms_random.value(1,1))) name,
nvl(lead(street) over (order by dbms_random.value(2,2)),
first_value(street) over (order by dbms_random.value(2,2))) street
FROM address) t2
ON (t1.address_id = t2.address_id)
WHEN matched THEN
UPDATE
SET t1.name = t2.name, t1.street = t2.street;
The individual random values are used so that both columns are shuffled separately (else they would stay together as a pair).