从表中随机返回n条记录

创建测试用表:

CREATE OR REPLACE VIEW V AS
SELECT 'a' AS c FROM dual
UNION ALL
SELECT 'b' AS c FROM dual
UNION ALL
SELECT 'c' AS c FROM dual
UNION ALL
SELECT 'd' AS c FROM dual
UNION ALL
SELECT 'e' AS c FROM dual;
SELECT * FROM v;

从表中随机返回n条记录

查询语句如下:

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

查询结果如下:

从表中随机返回n条记录

上一篇:JS执行机制详解,定时器时间间隔的真正含义


下一篇:使用javaScript解决asp.net中mvc使用ajax提交数组参数的匹配问题