Oracle隨機函數—dbms_random dom
1.基礎認識 ide
關於這些函數及DBMS_RANDOM包的文件都包含在SQLPlus中: select text from all_source where name = 'DBMS_RANDOM' 函數
and type = 'PACKAGE' order by line; orm
◆ TYPE num_array ◆ PROCEDURE terminate ◆ PROCEDURE seed string
◆ PROCEDURE initialize ◆ FUNCTION random it
◆ FUNCTION value RETURN NUMBER; class
◆ FUNCTION value (low IN NUMBER, high IN NUMBER) RETURN NUMBER; ◆ FUNCTION normal RETURN NUMBER; 基礎
◆ FUNCTION string (opt char, len NUMBER) RETURN VARCHAR2; 隨機數
2.應用舉例 select
SELECT DBMS_RANDOM.RANDOM FROM DUAL;
再進一步的要求,好比,產生一個0-100的隨機數,稍微變通一下就能夠了:
select abs(mod(dbms_random.random,100)) from dual
3.進階說明
dbms_random又有新函數了能夠實現這些功能 FUNCTION value RETURN NUMBER;
FUNCTION value (low IN NUMBER, high IN NUMBER) RETURN NUMBER; FUNCTION normal RETURN NUMBER;
FUNCTION string (opt char, len NUMBER) RETURN VARCHAR2;
產生N到M之間的隨機數
SELECT DBMS_RANDOM.VALUE(N,M) FROM DUAL;
缺省DBMS_RANDOM.VALUE返回0到1之間的隨機數
SQL> select dbms_random.value, dbms_random.value(55,100) from dual; VALUE DBMS_RANDOM.VALUE(55,100) --------------- -----------------------------