WEB开发网
开发学院数据库Oracle 教你轻松掌握随机抽取记录的方法 阅读

教你轻松掌握随机抽取记录的方法

 2007-09-14 12:40:27 来源:WEB开发网   
核心提示:问:能否给我介绍一种随机抽取记录的方法? 答:以下代码以抽取6条为例: create table t as select * fromall_objects where rownum <= 5000;set timing onselect object_name, object_idfrom ( select o

问:能否给我介绍一种随机抽取记录的方法?

答:以下代码以抽取6条为例:

create table t as select * from
all_objects where rownum <= 5000;
set timing on
select object_name, object_id
from ( select object_name, object_id
from t
where object_name like '%%'
order by dbms_random.random )
where rownum <= 6;
select object_name, object_id
from ( select object_name, object_id
from t sample ( 1 )
where object_name like '%%'
order by dbms_random.random )
where rownum <= 6;

Tags:轻松 掌握 随机

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接