---
title: "Oracle 随机取数据"
author: "winzenghua"
date: "2009-04-03T21:06:00Z"
tags: []
slug: "oracle"
draft: false
lastmod: "2009-04-03T21:06:00Z"
id: 987887
url: "https://java4gis.iteye.com/blog/987887"
---

select * from  
(  
select * fromhr.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 &lt; N;  
2）select * from (select * from hr.employees order by dbms\_random.value) where rownum&lt; N;