主頁(yè) > 知識(shí)庫(kù) > Oracle隨機(jī)函數(shù)之dbms_random使用詳解

Oracle隨機(jī)函數(shù)之dbms_random使用詳解

熱門標(biāo)簽:美圖秀秀地圖標(biāo)注 征服者火車站地圖標(biāo)注 人工智能地圖標(biāo)注自己能做嗎 開(kāi)封智能外呼系統(tǒng)廠家 外呼線路外顯本地號(hào)碼 百度地圖標(biāo)注素材 word地圖標(biāo)注方向 阿爾巴尼亞地圖標(biāo)注app 征服眼公司地圖標(biāo)注
dbms_random是oracle提供的一個(gè)隨機(jī)函數(shù)包,以下介紹一些dbms_random的常用示例:
dbms_random.value用法:
生成一個(gè)大于等于0,小于等于1的38位小數(shù)
復(fù)制代碼 代碼如下:

-- FUNCTION value RETURN NUMBER;
select dbms_random.value from dual;
SQL> select dbms_random.value from dual;
VALUE
----------
0.61011338

復(fù)制代碼 代碼如下:

-- FUNCTION value RETURN NUMBER;
select dbms_random.value from dual;
SQL> select dbms_random.value from dual;
VALUE
----------
0.61011338

生成一個(gè)指定范圍內(nèi)的數(shù)/ p>
復(fù)制代碼 代碼如下:

select dbms_random.value(100,0)
from dual;
SQL> select dbms_random.value(100,0)
2 from dual;
DBMS_RANDOM.VALUE(100,0)
------------------------
20.7742244285517

復(fù)制代碼 代碼如下:

-- FUNCTION value (low IN NUMBER, high IN NUMBER) RETURN NUMBER;
select dbms_random.value(100,0)
from dual;
SQL> select dbms_random.value(100,0)
2 from dual;
DBMS_RANDOM.VALUE(100,0)
------------------------
20.7742244285517

dbms_random.normal用法
獲取正態(tài)分布的隨機(jī)數(shù)
復(fù)制代碼 代碼如下:

select dbms_random.normal from dual;
SQL> select dbms_random.normal from dual;
NORMAL
----------
-1.7330759

復(fù)制代碼 代碼如下:

select dbms_random.normal from dual;
SQL> select dbms_random.normal from dual;
NORMAL
----------
-1.7330759

dbms_random.string用法
獲取指定字符串
復(fù)制代碼 代碼如下:

/* "opt" specifies that the returned string may contain:
'u','U' : upper case alpha characters only
'l','L' : lower case alpha characters only
'a','A' : alpha characters only (mixed case)
'x','X' : any alpha-numeric characters (upper)
'p','P' : any printable characters
*/
SQL>
select
dbms_random.string('u',10)
from dual
union all
select
dbms_random.string('U',10)
from dual
union all
select
dbms_random.string('l',10)
from dual
union all
select
dbms_random.string('L',10)
from dual
union all
select
dbms_random.string('a',10)
from dual
union all
select
dbms_random.string('A',10)
from dual
union all
select
dbms_random.string('x',10)
from dual
union all
select
dbms_random.string('X',10)
from dual
union all
select
dbms_random.string('P',10)
from dual
union all
select
dbms_random.string('P',10)
from dual;

復(fù)制代碼 代碼如下:

--FUNCTION string (opt char, len NUMBER)
/* "opt" specifies that the returned string may contain:
'u','U' : upper case alpha characters only
'l','L' : lower case alpha characters only
'a','A' : alpha characters only (mixed case)
'x','X' : any alpha-numeric characters (upper)
'p','P' : any printable characters
*/
SQL>
select
dbms_random.string('u',10)
from dual
union all
select
dbms_random.string('U',10)
from dual
union all
select
dbms_random.string('l',10)
from dual
union all
select
dbms_random.string('L',10)
from dual
union all
select
dbms_random.string('a',10)
from dual
union all
select
dbms_random.string('A',10)
from dual
union all
select
dbms_random.string('x',10)
from dual
union all
select
dbms_random.string('X',10)
from dual
union all
select
dbms_random.string('P',10)
from dual
union all
select
dbms_random.string('P',10)
from dual;

DBMS_RANDOM.STRING(‘U',10)
—————————-
TXREHAICRI
VDTMXZORVB
udavjpudfb
hvfqhjjdgz
tZoanQzxtX
siATLEZXQa
2LWWZ3H3L5
ZF6MKKG1R7
#\j5IPva(W
sJe/srX:ZB
10 rows selected
dbms_random.seed用法
–可以設(shè)置seed來(lái)確定隨機(jī)數(shù)的起始點(diǎn),對(duì)于相同的seed而言,隨機(jī)數(shù)的任意一次變化都將是確定的。
– 就是說(shuō),如果在某一時(shí)刻調(diào)用了seed,之后第一次產(chǎn)生的隨機(jī)數(shù)是4,第二次是6,第三次是1,
– 那么當(dāng)你再次調(diào)用相同的seed之后,一次產(chǎn)生的隨機(jī)數(shù)還是4、6、1
– seed有兩種,一種是數(shù)值型的,一種是字符型(最大長(zhǎng)度2000)的
復(fù)制代碼 代碼如下:

SELECT USERENV('SESSIONID')
FROM DUAL;
BEGIN
dbms_random.seed(6);
END;
/
SELECT DBMS_RANDOM.value
FROM DUAL
CONNECT BY LEVEL 10;

復(fù)制代碼 代碼如下:

SELECT USERENV('SESSIONID')
FROM DUAL;
BEGIN
dbms_random.seed(6);
END;
/
SELECT DBMS_RANDOM.value
FROM DUAL
CONNECT BY LEVEL 10;

--SESSION 1
復(fù)制代碼 代碼如下:

SQL> SELECT USERENV('SESSIONID')
2 FROM DUAL;
USERENV('SESSIONID')
--------------------
15140521
SQL> BEGIN
2 dbms_random.seed(100);
3 END;
4 /
PL/SQL procedure successfully completed
SQL> SELECT DBMS_RANDOM.value
2 FROM DUAL
3 CONNECT BY LEVEL 10;
VALUE
----------
0.53801770
0.67499536
0.65362270
0.76351985
0.29859834
0.40522032
0.99551636
0.39565580
0.18074760
9 rows selected

復(fù)制代碼 代碼如下:

SQL> SELECT USERENV('SESSIONID')
2 FROM DUAL;
USERENV('SESSIONID')
--------------------
15140521
SQL> BEGIN
2 dbms_random.seed(100);
3 END;
4 /
PL/SQL procedure successfully completed
SQL> SELECT DBMS_RANDOM.value
2 FROM DUAL
3 CONNECT BY LEVEL 10;
VALUE
----------
0.53801770
0.67499536
0.65362270
0.76351985
0.29859834
0.40522032
0.99551636
0.39565580
0.18074760
9 rows selected

--SESSION 2
復(fù)制代碼 代碼如下:

SQL> SELECT USERENV('SESSIONID')
2 FROM DUAL;
USERENV('SESSIONID')
--------------------
15140517
SQL> BEGIN
2 dbms_random.seed(100);
3 END;
4 /
PL/SQL procedure successfully completed
SQL> SELECT DBMS_RANDOM.value
2 FROM DUAL
3 CONNECT BY LEVEL 10;
VALUE
----------
0.53801770
0.67499536
0.65362270
0.76351985
0.29859834
0.40522032
0.99551636
0.39565580
0.18074760
9 rows selected

復(fù)制代碼 代碼如下:

SQL> SELECT USERENV('SESSIONID')
2 FROM DUAL;
USERENV('SESSIONID')
--------------------
15140517
SQL> BEGIN
2 dbms_random.seed(100);
3 END;
4 /
PL/SQL procedure successfully completed
SQL> SELECT DBMS_RANDOM.value
2 FROM DUAL
3 CONNECT BY LEVEL 10;
VALUE
----------
0.53801770
0.67499536
0.65362270
0.76351985
0.29859834
0.40522032
0.99551636
0.39565580
0.18074760
9 rows selected
您可能感興趣的文章:
  • sql server中隨機(jī)函數(shù)NewID()和Rand()
  • python中隨機(jī)函數(shù)random用法實(shí)例
  • php中隨機(jī)函數(shù)mt_rand()與rand()性能對(duì)比分析
  • perl寫的一個(gè)隨機(jī)編故事的程序(rand隨機(jī)函數(shù))
  • php數(shù)組函數(shù)序列 之shuffle()和array_rand() 隨機(jī)函數(shù)使用介紹
  • 如何產(chǎn)生真正的隨機(jī)函數(shù)?
  • 如何利用當(dāng)前時(shí)間生成隨機(jī)函數(shù)?
  • 詳解C語(yǔ)言中rand函數(shù)的使用

標(biāo)簽:孝感 酒泉 宜春 泰安 淮南 六安 葫蘆島 海北

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Oracle隨機(jī)函數(shù)之dbms_random使用詳解》,本文關(guān)鍵詞  Oracle,隨機(jī),函數(shù),之,dbms,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Oracle隨機(jī)函數(shù)之dbms_random使用詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Oracle隨機(jī)函數(shù)之dbms_random使用詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章