Oracle 随机取数据

来源:互联网 发布:linux mount共享盘 编辑:程序博客网 时间:2024/05/29 17:19

select * from
(
select * from hr.employees order by dbms_random.value

)
where rownum = 1;

 

注:dbms_random包需要手工安装,位于$ORACLE_HOME/rdbms/admin/dbmsrand.sql
dbms_random.value(100,200)可以产生100到200范围的随机数

另附随机抽取前N条记录的常用方法
8i以上版本
1)select * from (select * from hr.employees order by sys_guid()) where rownum < N;
2)select * from (select * from hr.employees order by dbms_random.value) where rownum< N;