当前位置: 代码迷 >> Oracle开发 >> 从表中随机回来n条记录
  详细解决方案

从表中随机回来n条记录

热度:189   发布时间:2016-04-24 06:24:40.0
从表中随机返回n条记录

创建测试用表:

CREATE OR REPLACE VIEW V ASSELECT 'a' AS c FROM dualUNION ALLSELECT 'b' AS c FROM dualUNION ALLSELECT 'c' AS c FROM dualUNION ALLSELECT 'd' AS c FROM dualUNION ALLSELECT 'e' AS c FROM dual;SELECT * FROM v;

查询语句如下:

SELECT c  FROM (SELECT c FROM v ORDER BY DBMS_RANDOM.VALUE()) WHERE ROWNUM < 3;

查询结果如下:

  相关解决方案