隨機抽批
select * from (select * from scott.emp where deptno=30 order by dbms_random.random ) where rownum<4;
可將4換成需要顯示的(條數+1);
參考:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_random.htm#i998925
DBMS_RANDOM
The DBMS_RANDOM package provides a built-in random number generator. DBMS_RANDOM is not intended for cryptography.
This chapter contains the following topics:
-
-
Security Model
-
Operational Notes
-
Using DBMS_RANDOM
Security Model
This package should be installed as SYS. By default, the package is initialized with the current user name, current time down to the second, and the current session.
Operational Notes
-
DBMS_RANDOM.RANDOM produces integers in [-2^^31, 2^^31).
-
DBMS_RANDOM.VALUE produces numbers in [0,1) with 38 digits of precision.
DBMS_RANDOM can be explicitly initialized, but does not need to be initialized before calling the random number generator. It will automatically initialize with the date, userid, and process id if no explicit initialization is performed.
If this package is seeded twice with the same seed, then accessed in the same way, it will produce the same results in both cases.
In some cases, such as when testing, you may want the sequence of random numbers to be the same on every run. In that case, you seed the generator with a constant value by calling one of the overloads of DBMS_RANDOM.SEED. To produce different output for every run, simply to omit the call to "Seed" and the system will choose a suitable seed for you.
Summary of DBMS_RANDOM Subprograms
Table 75-1 DBMS_RANDOM Package Subprograms
Subprogram | Description |
---|---|
Initializes the package with a seed value |
|
Returns random numbers in a normal distribution |
|
Generates a random number |
|
Resets the seed |
|
Gets a random string |
|
Terminates package |
|
This function gets a random number, greater than or equal to 0 and less than 1, with 38 digits to the right of the decimal (38-digit precision), while the overloaded function gets a random Oracle number x, where x is greater than or equal to low and less than high |
Note:
The INITIALIZE Procedure, RANDOM Procedure and the TERMINATE Procedure are all obsolete and, while currently supported, are included in this release for legacy reasons only.INITIALIZE Procedure
This procedure initializes the generator (but see Usage Notes).
Syntax
DBMS_RANDOM.INITIALIZE ( val IN BINARY_INTEGER);
Pragmas
PRAGMA restrict_references (initialize, WNDS)
Parameters
Table 75-2 INITIALIZE Procedure Parameters
Parameter | Description |
---|---|
val |
The seed number used to generate a random number. |
Usage Notes
This procedure is obsolete as it simply calls the SEED Procedures.
NORMAL Function
This function returns random numbers in a standard normal distribution.
Syntax
DBMS_RANDOM.NORMAL RETURN NUMBER;
Pragmas
PRAGMA restrict_references (normal, WNDS)
Return Values
Table 75-3 NORMAL Procedure Parameters
Parameter | Description |
---|---|
number |
Returns a random number. |
RANDOM Procedure
This procedure generates a random number (but see Usage Notes).
Syntax
DBMS_RANDOM.RANDOM RETURN binary_integer;
Pragmas
PRAGMA restrict_references (random, WNDS)
Return Values
Table 75-4 RANDOM Procedure Parameters
Parameter | Description |
---|---|
binary_integer |
Returns a random integer greater or equal to -power(2,31) and less than power(2,31). |
Usage Notes
This procedure is obsolete and, although it is currently supported, it should not be used.
SEED Procedures
This procedure resets the seed.
Syntax
DBMS_RANDOM.SEED ( seed IN BINARY_INTEGER); DBMS_RANDOM.SEED ( seed IN VARCHAR2);
Pragmas
PRAGMA restrict_references (seed, WNDS);
Parameters
Table 75-5 SEED Procedure Parameters
Parameter | Description |
---|---|
seed |
Seed number or string used to generate a random number. |
Usage Notes
The seed can be a string up to length 2000.
STRING Function
This function gets a random string.
Syntax
DBMS_RANDOM.STRING opt IN CHAR, len IN NUMBER) RETURN VARCHAR2;
Pragmas
PRAGMA restrict_references (string, WNDS)
Parameters
Table 75-6 STRING Function Parameters
Parameter | Description |
---|---|
opt |
Specifies what the returning string looks like:
Otherwise the returning string is in uppercase alpha characters. |
len |
The length of the returning string. |
Return Values
Table 75-7 STRING Function Return Values
Parameter | Description |
---|---|
VARCHAR2 |
Returns a VARCHAR2. |
TERMINATE Procedure
When you are finished with the package, call the TERMINATE procedure (but see Usage Notes)
Syntax
DBMS_RANDOM.TERMINATE
Usage Notes
This procedure performs no function and, although it is currently supported, it is obsolete and should not be used.
VALUE Functions
The basic function gets a random number, greater than or equal to 0 and less than 1, with 38 digits to the right of the decimal (38-digit precision). Alternatively, you can get a random Oracle number x, where x is greater than or equal to low and less than high.
Syntax
DBMS_RANDOM.VALUE RETURN NUMBER; DBMS_RANDOM.VALUE( low IN NUMBER, high IN NUMBER) RETURN NUMBER;
Parameters
Table 75-8 VALUE Function Parameters
Parameter | Description |
---|---|
low |
The lowest number in a range from which to generate a random number. The number generated may be equal to low. |
high |
The highest number below which to generate a random number. The number generated will be less than high. |
Return Values
Table 75-9 VALUE Function Return Values
Parameter | Description |
---|---|
NUMBER |
Returns an Oracle Number. |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29519108/viewspace-1421140/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 隨機抽獎隨機
- 使用Hive隨機抽樣Hive隨機
- numpy2.隨機抽樣隨機
- JavaScript實現隨機抽獎效果JavaScript隨機
- Java實現隨機抽獎的方法有哪些Java隨機
- C#實現的簡單的隨機抽號器C#隨機
- 隨機抽樣一致性(RANSAC)演算法詳解隨機演算法
- 以太坊 solidity 隨機抽獎合約——搏一搏,單車變摩托Solid隨機
- 用Python寫演算法 | 蓄水池演算法實現隨機抽樣Python演算法隨機
- 隨機之美,隨機森林隨機森林
- [Z]Oracle 的隨機數、隨機日期和時間、隨機字串Oracle隨機字串
- python生成隨機數、隨機字串Python隨機字串
- 隨機題隨機
- 隨機排序隨機排序
- 隨機數隨機
- 從oracle表中隨機取記錄,產生隨機數和隨機字串Oracle隨機字串
- [隨機數詳解]生成一個隨機數,生成指定範圍的隨機數及隨機陣列去重隨機陣列
- 批處理定時關機
- 遊戲審批規則變動:限制每日抽取次數,十連抽最多3次遊戲
- Linux Shell 生成隨機數和隨機字串Linux隨機字串
- Python隨機數與隨機字串詳解Python隨機字串
- 條件隨機場CRF(一)從隨機場到線性鏈條件隨機場條件隨機場CRF
- matlab產生隨機數或隨機矩陣Matlab隨機矩陣
- 生成隨機排列隨機
- 隨機雙色球隨機
- 隨機數(三)隨機
- 隨機數(一)隨機
- 隨機數(二)隨機
- 生成隨機數隨機
- php隨機字串PHP隨機字串
- groovy : 隨機數隨機
- 隨機選組隨機
- 隨機矩陣隨機矩陣
- 隨機事件3.7隨機事件
- 運用JS 實現隨機點名 (隨機點名)JS隨機
- 隨機範圍小數和隨機範圍整數隨機
- (轉)Oracle的隨機數、隨機日期和時間、隨機字串及造資料匿名過程Oracle隨機字串
- Flash手機抽獎程式設計:基礎思路程式設計