These are the 3 ways i've found to do random selections in oracle. If there's a better way... SOMEONE tell me.
1) NO WHERE CLAUSE, 10%:
select * from my_table sample(10)
The other two aren't so pretty...
2) WHERE CLAUSE, no order clause. When using ado, you can do a recordcount * 10% and just print that many records:
1 2 3 4
| select my_table.*
from my_table
[WHERE CLAUSE]
order by mod(DBMS_RANDOM.Random,50)+50 |
3) WHERE CLAUSE, order clause. Then, either through an outer query or when running through a loop, just print the records that have RANDOM less than 10
1 2 3 4 5
| select mod(DBMS_RANDOM.Random,50)+50 as RANDOM,
my_table.*
from my_table
[WHERE CLAUSE]
order by page,revision |
Partager