文档课题:使用dbms_redact对表字段进行加密
数据库:oracle 19.13 多租户
1、准备数据
leo@ORCLPDB> create table TEST1 (id NUMBER,name VARCHAR2(10));
leo@ORCLPDB> insert into test1 values (1,'测试');
leo@ORCLPDB> insert into test1 values (2,'你好呀');
2、添加策略
2.1、添加策略a
sys@ORCLCDB> BEGIN
DBMS_REDACT.ADD_POLICY(
object_schema => 'LEO',
object_name => 'TEST1',
column_name => 'NAME',
policy_name => 'redact_policy_attrvalue',
function_type => DBMS_REDACT.FULL,
expression => '1=1');
END;
/
2.2、数据验证
leo@ORCLPDB> select * from test1;
ID NAME
---------- ----------------------------
1 测试
2 你好呀
alina@ORCLPDB> select * from leo.test1;
ID NAME
---------- ----------------------------
1
2
小结:使用策略a后,其它用户无法查看加密字段,但加密字段对所属用户无效.
2.3、删除策略
sys@ORCLCDB> exec dbms_redact.drop_policy(object_schema=>'LEO',object_name=>'TEST1',policy_name=>'redact_policy_attrvalue');
2.4、添加策略b
sys@ORCLCDB> BEGIN
DBMS_REDACT.ADD_POLICY(
object_schema => 'LEO',
object_name => 'TEST1',
column_name => 'NAME',
policy_name => 'redact_policy_attrvalue',
function_type => DBMS_REDACT.RANDOM,
expression => '1=1');
END;
/
2.5、数据验证
leo@ORCLPDB> select * from test1;
ID NAME
---------- ----------------------------
1 测试
2 你好呀
alina@ORCLPDB> select * from leo.test1;
ID NAME
---------- ----------------------------
1 X,Tm@4
2 vT/"(=d*~
小结:使用策略b后,其它用户查看加密字段显示乱序,但加密字段对所属用户无效.