如果你要的是记录一级的逻辑随机,取过的记录还可以再取,可以这样做1、建立用于随机选记录的辅助表
create table ramd as select rownum rnum, rowid rid from your_table;2、用 DBMS_RANDOM.RANDOM 生成 1 到 [select count(*) from ramd] 的数字 i3、得到你要的记录
select * from your_table where rowid = (select rid from ramd where rnum = i)

解决方案 »

  1.   

    select * from your_table where rownum=trunc(dbms_random.value(1,10))
      

  2.   

    to  jiezhi(西域浪子)
    这种写法是错误的。rownum在大于1的时候,=是选不出结果的。
    select * from your_table where rownum=trunc(dbms_random.value(1,10))
    不过可以改写成
    select * from (select rowid id,t.* from your_table t) 
    where id=trunc(dbms_random.value(1,10))
      

  3.   

    关于随机抽取记录的办法还有
    select * from (select * from your_table order by sys_guid()) where rownum < 2;(8i支持) select * from (select * from your_table order by dbms_random.value)where rownum < 2;
      

  4.   

    从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
      

  5.   

    sorry,不知道是不是我没说清楚,不可以重复,每次取得的顺序都要求不一样!!!