首先去到以个随机数A,然后; select * from table_name where rownum = A;
比如要取第n条: select * from table where rownum<=n minus select * from table where rownum<n;
能不能向sqlserver似的直接用一条sql语句实现
随机(一定条数记录范围内)选取一条记录: select a.* from (select rownum rn,a.* from t_jg a)a where rn=(select round(dbms_random.value(1,17)) rn from dual);这句又可以随机选出(在1到17条范围内,一条没有,一条,多条)记录 select a.* from (select rownum rn,a.* from t_jg a)a where rn=round(dbms_random.value(1,17));
从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 table_name where rownum = A;
select * from table where rownum<=n
minus
select * from table where rownum<n;
随机(一定条数记录范围内)选取一条记录:
select a.* from (select rownum rn,a.* from t_jg a)a where rn=(select round(dbms_random.value(1,17)) rn from dual);这句又可以随机选出(在1到17条范围内,一条没有,一条,多条)记录
select a.* from (select rownum rn,a.* from t_jg a)a where rn=round(dbms_random.value(1,17));
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;