Oracle使用sample獲得隨機結果集

2021-08-19 20:37:06 字數 816 閱讀 4741

oracle使用sample獲得隨機結果集

語法: sample [ block ](sample_percent)[ seed (seed_value) ]

sample選項:表示按行取樣來執行乙個全表掃瞄,oracle從表中讀取特定百分比的記錄,並判斷是否滿足where子句以返回結果。

block: 表示使用隨機塊例舉而不是隨機行例舉。

sample_percent:是隨機獲取一張表中記錄的百分比。比如值為10,那就是表中的隨機的百分之10的記錄。

值必須大於等於.000001,小於100。

seed:表示從哪條記錄返回,類似於預先設定例舉結果,因而每次返回的結果都是固定的。該值必須介於0和4294967295之間。

例子:從表zeeno中「全表掃瞄」隨機抽取10%的記錄,隨機查詢5條記錄

sql>select object_name from zeeno sample(10) where rownum<6

從表zeeno中「取樣表掃瞄」隨機抽取10%的記錄,隨機查詢5條記錄

sql> select object_name from zeeno sample block(10) where rownum<6;

使用seed,返回固定的結果集。從表zeeno中「取樣表掃瞄」隨機抽取10%的記錄,隨機查詢5條記錄。

sql> select object_name from zeeno sample(10) seed(10) where rownum<6;

注意以下幾點:

1.sample只對單錶生效,不能用於表連線和遠端表

2.sample會使sql自動使用cbo

乙個sample學會使用epoll

include include include include include include include include include include include include define max event number 1024 define tcp buffer size 51...

多執行緒之使用互斥訊號量Sample

code author lin yiqian created 2009 09 16 describe 執行緒結束時會自動釋放互斥量 演示 include include using namespace std dword winapi threadfun lpvoid lpparameter han...

mysql獲取變數 使用變數從mysql獲取資料

我正在使用此 word post word wid post id print print sql select url imgsrch from p url imgsrch where word id wid order by rand limit 5 result mysql query sql...