当前位置:网站首页>金仓数据库 KingbaseES 插件DBMS_RANDOM
金仓数据库 KingbaseES 插件DBMS_RANDOM
2022-06-25 10:45:00 【沉舟侧畔千帆过_】
目录
1. DBMS_RANDOM
1.1. DBMS_RANDOM介绍
KingbaseES提供了DBMS_RANDOM系统包下定义的随机数据产生的功能。DBMS_RANDOM系统包提供一个随机数或者字符的生成器。
使用时需要create extension dbms_random,不需要时drop extension dbms_random即可。
下表列出了DBMS_RANDOM系统包并简要的表述了它们。
表 1 DBMS_RANDOM软件包子程序和函数
子程序/函数 | 描述 |
INITIALIZE | 使用一个种子值来初始化包 |
NORMAL Function | 产生标准的正态分布函数 |
RANDOM Function | 产生一个随机整数 |
SEED Procedure | 重置随机数种子 |
STRING Function | 产生一个随机字符串 |
TERMINATE Procedure | 提供语法上的兼容不执行任何操作 |
VALUE Function | 产生指定范围的随机数 |
2. INITIALIZE Procedure
使用一个种子值来初始化DBMS_RANDOM包,默认情况下,DBMS_RANDOM包是根据用户、时间、会话来初始化。Initialize这个函数已经过时,虽然目前受到支持,但考虑历史遗留原因和兼容性保留此初始化方式。
语法格式:
DBMS_RANDOM.INITIALIZE(init INTEGER);
参数说明:
表 2 initialize 参数
参数 描述 init 随机数种子值
返回值说明:
VOID
示例:
CALL dbms_random.initialize(8);
3. NORMAL Function
产生标准的正态分布函数,此正态分布的标准差为1,期望值为0。
语法格式:
DBMS_RANDOM.NORMAL();
参数说明:
无参
返回值说明:DOUBLE
示例:
SELECT dbms_random.normal();
4. RANDOM Function
产生一个随机整数,这个函数已经过时了,虽然目前还支持,但不应该使用它,考虑兼容性保留此函数。
语法格式:
DBMS_RANDOM.RANDOM();
参数说明:
无参
返回值说明:
NTEGER
示例:
CALL dbms_random.random();
5. SEED Procedure
重置种子,类似于initialize函数,initialize函数已经被淘汰。 seed函数同时支持数值和字符作为种子值,而initialize只支持数值。
语法格式:
DBMS_RANDOM.SEED(i INTEGER);
DBMS_RANDOM.SEED(t TEXT);
参数说明:
表 3 seed 参数
参数 描述 i 随机数种子值 t 随机数字符种子值
返回值说明:
表 4 seed 返回值
函数 类型 SEED(i INTEGER) VOID SEED(t TEXT) VOID
示例:
CALL dbms_random.seed(8);
CALL dbms_random.seed('test');
6. STRING Function
获取一个随机字符串,第一个参数的是字符串的格式,第二个参数是指字符串的长度。 长度最大为5000,参数如果超过5000会自动以5000处理。
语法格式:
DBMS_RANDOM.STRING(type TEXT,len INTEGER);
参数说明:
表 5 string 参数
表 6 type参数对应含义
参数 描述 type 产生字符串的类型 len 产生字符串的长度
'x','X' | 返回大写字母和数字的字符串 |
'p','P' | 返回任何可打印字符的字符串 |
返回值说明:
TEXT
示例:
SELECT dbms_random.string('U',5);
SELECT dbms_random.string('P',2);
SELECT dbms_random.string('x',4);
SELECT dbms_random.string('a',2);
SELECT dbms_random.string('l',3);
7. TERMINATE Procedure
原功能为使用完dbms_random包的时候执行此函数,但是现在此函数不执行任何功能,为了语法兼容保留。
语法格式:
DBMS_RANDOM.TERMINATE();
参数说明:
无参
返回值说明:
VOID
示例:
CALL dbms_random.terminate();
8. VALUE Function
第一种无参的使用方式是获取一个大于或者等于0且小于1的随机数,精度为16位的小数。
第二使用方式可以指定最小值和最大值,返回值的范围大于或者等于low,小于high,精度同为16位小数。
语法格式:
DBMS_RANDOM.VALUE();
DBMS_RANDOM.VALUE(low INTEGER,high INTEGER);
参数说明:
表 7 value 参数
参数 描述 low 产生的随机数最小值 high 产生的随机数最大值
返回值说明:
表 8 value 返回值
函数 类型 VALUE() VOID VALUE(low INTEGER,high INTEGER) VOID
示例:
SELECT dbms_random.value();
SELECT dbms_random.value(10,15);
边栏推荐
- 3 Questions par jour (3) - vérifier l'existence d'entiers et de leurs doubles
- 无心剑中译伊玛·拉扎罗斯《新巨人·自由女神》
- [200 opencv routines] 210 Are there so many holes in drawing a straight line?
- Identityserver4 definition concept
- Coscon'22 lecturer solicitation order
- [observation] objectscale: redefining the next generation of object storage, reconstruction and innovation of Dell Technology
- Oracle query comes with JDK version
- Kotlin arrays and collections (1) {create arrays, use arrays, use for in loops to traverse arrays, use array indexes, and multi-dimensional arrays}
- Oracle彻底卸载的完整步骤
- OODA工作法
猜你喜欢
Chinese translation of IMA Lazarus' the new giant, the goddess of Liberty
[paper reading | depth] role based network embedding via structural features reconstruction with degree regulated
MCU development -- face recognition application based on esp32-cam
Previous string inversion topic
单片机开发---基于ESP32-CAM的人脸识别应用
Complete steps for a complete Oracle uninstall
How to install SSL certificates in Microsoft Exchange 2010
Netease's open source distributed storage system curve officially became the CNCF sandbox project
Ouverture de l'inscription | le troisième marathon des hackers de pagaie est arrivé comme prévu.
CSRF攻击
随机推荐
ES 学习
[paper reading | depth] role based network embedding via structural features reconstruction with degree regulated
Dependent properties, dependent additional properties, and type conversions
報名開啟|飛槳黑客馬拉松第三期如約而至,久等啦
Is it safe to open an account with Guangzhou securities by mobile phone?
Checking whether the double value is an integer - Swift - checking if a double value is an integer - swift
On binary tree
Handling of NPM I installation problems
QT: parsing JSON
COSCon'22 讲师征集令
[image fusion] image fusion based on morphological analysis and sparse representation with matlab code
网络远程访问的方式使用树莓派
WPF binding expression and binding data source (I)
16 种企业架构策略
Google Earth Engine (Gee) - evaluate réalise le téléchargement en un clic de toutes les images individuelles dans la zone d'étude (certaines parties de Shanghai)
[today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
The real difference between i++ and ++i
OpenCV学习(二)---树莓派上安装opencv
Daily Mathematics Series 52: February 20
Yolov5 changing the upper sampling mode