select * from t1 where rownum<100 order by dbms_random.value
select * from t1 where rownum<abs(mod(dbms_random(),200))
我这样求,对不对: select * from (select * from t1 order by dbms_random.value) where rownum<101 order by id
select * from (select * from your_table order by sys_guid()) where rownum <= 100;(8i支持)
9i:select * from (select * from your_table order by dbms_random.value)where rownum <=100
从zyz2表中随机取出两条纪录: SQL> select * from zyz2; ID P1 P2 ---------- ---------- ---------- 1 211 212 2 12 14 4 241 242 2 145 1 11 3 17 26 rows selected.Elapsed: 00:00:00.50 SQL> select id,p1,p2 from (select zyz2.*,dbms_random.random num from zyz2 order by num) where rownum<3; ID P1 P2 ---------- ---------- ---------- 2 12 14 1 211 212Elapsed: 00:00:00.30 SQL> select id,p1,p2 from (select zyz2.*,dbms_random.random num from zyz2 order by num) where rownum<3; ID P1 P2 ---------- ---------- ---------- 3 17 2 2 12 14 8i以上 select * from (select * from ur_table order by sys_guid()) where rownum<n; select * from (select * from ur_table order by dbms_random.value) where rownum<n;
select * from (select * from t1 order by dbms_random.value) where rownum<101 order by id
SQL> select * from zyz2;
ID P1 P2
---------- ---------- ----------
1 211 212
2 12 14
4 241 242
2 145
1 11
3 17 26 rows selected.Elapsed: 00:00:00.50
SQL> select id,p1,p2 from (select zyz2.*,dbms_random.random num from zyz2 order
by num) where rownum<3; ID P1 P2
---------- ---------- ----------
2 12 14
1 211 212Elapsed: 00:00:00.30
SQL> select id,p1,p2 from (select zyz2.*,dbms_random.random num from zyz2 order
by num) where rownum<3; ID P1 P2
---------- ---------- ----------
3 17 2
2 12 14
8i以上
select * from (select * from ur_table order by sys_guid()) where rownum<n;
select * from (select * from ur_table order by dbms_random.value) where rownum<n;