如何从oracle的表中随机抽取一些记录

方法一:

select * from t sample(10); –return 10% of rows of the table

select * frmo t sample(10); –return 10% of all formated blocks of the table

方法二:

–Order By dbms_random.value ,为结果集的每一行计算一个随机数,dbms_random.value 是结果集的一个列(虽然这个列并不在select list 中),然后根据该列排序,得到的顺序自然就是随机的啦。

select * from (

select * from t order by dbms_random.value

) where rownum <= 10


参考文章:

Order by dbms_random.value on asktom.com

Can one select a random collection of rows from a table?

Order By dbms_random.value on itpub.net

Comments are closed.