先貼一段sql:sql
SELECT *
FROM check_for_busi_result SAMPLE BLOCK (10) SEED (11)
WHERE ROWNUM <= 5;
/* 1.sample只對單表生效,不能用於錶鏈接、遠程表、視圖
2.sample會使SQL自動使用CBO */
/* sample 按記錄採樣 seed(3) 返回固定的結果集 */
select count(*) from check_for_busi_result sample(18);
SELECT *
FROM check_for_busi_result SAMPLE (18)
WHERE ROWNUM <= 5;
/* SAMPLE BLOCK (18) 按數據塊採樣 「採樣表掃描」隨機抽取10%的記錄,再從中隨機查詢5條記錄 */
select count(*) from check_for_busi_result sample block(18) ;
SELECT *
FROM check_for_busi_result SAMPLE BLOCK (18)
WHERE ROWNUM <= 5;
/* 獲取一個隨機數
--(0-10的整數) */
SELECT TRUNC (DBMS_RANDOM.VALUE (0, 10)) randomNum FROM DUAL;
取表隨機數據
SELECT *
FROM ( SELECT *
FROM check_for_busi_result
ORDER BY DBMS_RANDOM.VALUE)
WHERE ROWNUM <= 3
SELECT *
FROM ( SELECT *
FROM check_for_busi_result
ORDER BY DBMS_RANDOM.VALUE(1,3))
WHERE ROWNUM <= 3
SELECT *
FROM ( SELECT *
FROM check_for_busi_result
ORDER BY DBMS_RANDOM.random)
WHERE ROWNUM <= 3
SELECT *
FROM ( SELECT *
FROM check_for_busi_result
ORDER BY sys_guid())
WHERE ROWNUM <= 3dom
貼個資源博客:https://blog.csdn.net/bbliutao/article/details/7727322;ui