今天是2021-3-14,有些疲惫。在3月12号快下班的时候突然又被拉住,说是否可以对公司重要的一张业务表关键业务数据进行下脱敏,既保证了原先数据类型又能对重要客户数据进行模糊处理,便于后期进行应用测试。也就产生了这篇文章,一方面自己在学习下,另一方面当做个笔记了。
对于脱敏,个人感觉目前市面上厂家很多,通过各种自带函数、正则表达式等等整合成对应产品,感觉还是不错的。在这个背景下,让我突然想到了oracle随机数这个东西。简单介绍下oracle 的SYS_GUID() 函数和DBMS_RANDOM包
一、SYS_GUID函数。
一般在很多客户系统表中,经常看到这个函数的使用,主要目的是一般作为主键。通常在插入数据的时候体现,例如:
insert into emp01(ID,name,sal) values(sys_guid(),'LUCY',20000);
该函数所在位置:Application Development--->SQL and PL/SQL-->SQL Language Reference->Fuctions
Purpose
SYS_GUID generates and returns a globally unique identifier (RAW value) made up of 16 bytes. On most platforms, the generated identifier consists of a host identifier, a process or thread identifier of the process or thread invoking the function, and a nonrepeating value (sequence of bytes) for that process or thread.
总之:是个16字节的唯一编码,依据一些主机信息、进程、线程等。。
使用很简单,直接用就可以了。
SYS@PROD> select sys_guid() from dual;
SYS_GUID()
--------------------------------
BD7FB10321B30B03E0537906A8C0B97A
SYS@PROD> r
1* select sys_guid() from dual
SYS_GUID()
--------------------------------
BD7FB10321B40B03E0537906A8C0B97A
SYS@PROD> r
1* select sys_guid() from dual
SYS_GUID()
--------------------------------
BD7FB10321B50B03E0537906A8C0B97A
SYS@PROD>
二、DBMS_RANDOM
该函数所在位置:Application Development--->SQL and PL/SQL-->PL/SQL Packages and Types Reference
The DBMS_RANDOM
package provides a built-in random number generator. DBMS_RANDOM
is not intended for cryptography.
说明:该函数是oracle内置的一个随机数生成器,并不是加密用的。
有几个子程序已经废弃了,oracle有说明也不建议用。
Note:
Oracle recommends that you do not use deprecated procedures in new applications. Support for deprecated features is for backward compatibility only.
The following subprograms are deprecated with Oracle Database 11g:
INITIALIZE Procedure
RANDOM Function
TERMINATE Procedure
子程序有:
Subprogram | Description |
---|---|
Initializes the package with a seed value (11GR1废弃) |
|
Returns random numbers in a normal distribution |
|
Generates a random number(11GR1废弃) |
|
Resets the seed |
|
Gets a random string |
|
Terminates package(11GR1废弃) |
|
Gets a random num |