Oracle的dbms_random各函数使用 1、包定义: sqlgt;desc dbms_random Element Type ---------- --------- SEED PROCED
Oracle的dbms_random各函数使用
1、包定义:
sql>desc dbms_random
Element Type
---------- ---------
SEED PROCEDURE
VALUE FUNCTION
NORMAL FUNCTION
STRING FUNCTION
INITIALIZE PROCEDURE
RANDOM FUNCTION
TERMINATE PROCEDURE
NUM_ARRAY TYPE
2、使用举例:
a、value() 用于返回两个数值之间的随机数,,value(low,high)
SQL> select dbms_random.value() from dual;
DBMS_RANDOM.VALUE() 默认是从0到1间的数
-------------------
0.0536824248407651
SQL> select dbms_random.value(10,100) from dual;
DBMS_RANDOM.VALUE(10,100)
-------------------------
29.2420951206225
b、random() 返回的值介于2的31次方和-2的31次方之间的整形数值
SQL> select dbms_random.random() from dual;
DBMS_RANDOM.RANDOM()
--------------------
2071097056
SQL> select dbms_random.random() from dual;
DBMS_RANDOM.RANDOM()
--------------------
-1589187025
c、string('parameter',length)
SQL> select dbms_random.string('a',10) from dual; --all返回不分大小写的字母字符串
DBMS_RANDOM.STRING('A',10)
--------------------------------------------------------------------------------
eDvKaqNWII
SQL> select dbms_random.string('u',10) from dual; --upper返回大写字母字符串
DBMS_RANDOM.STRING('U',10)
--------------------------------------------------------------------------------
KPGNYTWDGA
SQL> select dbms_random.string('l',10) from dual; --little小写字母
DBMS_RANDOM.STRING('L',10)
--------------------------------------------------------------------------------
zehtdserww
SQL> select dbms_random.string('x',10) from dual; ---大写字母加数字
DBMS_RANDOM.STRING('X',10)
--------------------------------------------------------------------------------
3Z7DBA4S8I
SQL> select dbms_random.string('p',10) from dual; --print 所有可以打印的字符