DBMS_RANDOM

開發過程中經常會有產生隨機數的需求,而oracle本身自帶的有這樣的功能,下面介紹一下擁有此功能的包DBMS_RANDOM,主要以官方文檔來說明:

The DBMS_RANDOM package provides a built-in random number generator.

該包裏包含了幾個子程序,這裏僅僅介紹兩個:

RANDOM function

This procedure is deprecated. Although currently supported, it should not be used. It generates and returns a random number.

Syntax

DBMS_RANDOM.RANDOM
   RETURN binary_integer;

Return value

A random BINARY_INTEGER value greater than or equal to -power(2,31) and less than power(2,31)



VALUE function

One version returns 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). The other version returns a random Oracle Database NUMBER value x, where x is greater than or equal to the specified low value and less than the specified high value.

Syntax

DBMS_RANDOM.VALUE
  RETURN NUMBER;

DBMS_RANDOM.VALUE(
  low  IN  NUMBER,
  high IN  NUMBER)
RETURN NUMBER;

Parameters


Parameter Description

low

Lower limit of the range in which to generate a random number

high

Upper limit of the range in which to generate a random number


Return value

NUMBER value that is the generated random number



舉例:round(dbms_random.value(0,18),0)   就可以返回大於等於0且小於18的整數;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章