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

来源:岁月联盟 编辑:zhuzhu 时间:2007-09-14

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

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

 

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