随机取表中数据

在pl/sql中有张1000条记录的表。如果想随机抽取其中50条记录该如何操作呢?[@more@]

利用select *from (select *from t order by dbms_random.value) where rownum<10;


for example:

SQL> select count(*) from all_objects;

COUNT(*)
----------
23910


SQL> create table seaman_t as select * from all_objects where rownum <=2000;

Table created.


SQL> select object_name, object_id from ( select object_name, object_id from seaman_t where object_name like '%%' order by dbms_random.random ) where rownum <= 4;

OBJECT_NAME OBJECT_ID
------------------------------ ----------
GV_$LOADPSTAT 1858
USER_CONS_COLUMNS 1363
DBMS_AQ_SYS_EXP_INTERNAL 2455
EXU8CSNU 1620

SQL> select object_name, object_id from ( select object_name, object_id from seaman_t where object_name like '%%' order by dbms_random.random ) where rownum <= 4;

OBJECT_NAME OBJECT_ID
------------------------------ ----------
ALL_TAB_COL_STATISTICS 1300
USER_SUMMARY_AGGREGATES 2057
oracle/ODCI/ODCIPredInfoRef 7101312
EXU81CSC 1846

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/119395/viewspace-908196/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/119395/viewspace-908196/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值