简体   繁体   English

oracle 12c 中的数据屏蔽

[英]Data masking in oracle 12c

how to update the values of particular columns of a table after masking in oracle 12c?在oracle 12c中屏蔽后如何更新表的特定列的值?

My table:我的表:

detail_table(
 id number,
 source_num varchar2(20), 
 destination_num varchar2(20)
) 

it contains 250 million records.它包含 2.5 亿条记录。 How to mask the columns source_num, destination_num like this:如何像这样屏蔽列 source_num、destination_num:

                source_num 
before masking: 1234567896
after masking:  123456XXXX (excluding first six characters all need to be replaced by X).

the same rule will be applied for destination_num also.the existing values in the table need to replaced by the masked values.相同的规则也将应用于 destination_num。表中的现有值需要替换为掩码值。 i have read some articles regarding data redaction in oracle 12c but its mentioned as only we can select the masked data but no the updates.我已经阅读了一些关于 oracle 12c 中数据编辑的文章,但提到它是因为只有我们可以选择被屏蔽的数据而不能选择更新。

WITH tst AS
  (SELECT '1234567890' AS col FROM dual
  )
SELECT col    AS col1,
  LENGTH(col) AS col2,
  REGEXP_REPLACE(col, '.', 'x', 7) col3,
  LENGTH(REGEXP_REPLACE(col, '.', 'x', 7)) col4
FROM tst

I don't know what you mean by 25 Cr records .我不知道你所说的25 Cr 记录是什么意思。 Assuming it's a lot of data (millions) I would recommend:假设有很多数据(数百万),我建议:

  • creating a new table with the updated columns使用更新的列创建一个新表
  • dropping the first table (keep in mind indexes and other stuff which need to be disabled during this operation)删除第一个表(请记住在此操作期间需要禁用的索引和其他内容)
  • renaming the new table to be like the original将新表重命名为原始表

How to create the new table:如何创建新表:

CREATE TABLE detail_table_1 AS
SELECT id,
  REGEXP_REPLACE(source_num, '.', 'x', 7) AS source_num,
  REGEXP_REPLACE(destination_num , '.', 'x', 7) AS destination_num 
FROM detail_table
update detail_table 
  set source_num = rpad(substr(source_num, 1,6), length(source_num),'X')
     ,destination_num = rpad(substr(destination_num , 1,6), length(destination_num ),'X'); 

add update for both columns destination_num and source_numdestination_numsource_num列添加更新

I think this one is shorter:我认为这个更短:

update detail_table
set source_num = REGEXP_REPLACE(source_num, '.', 'x', 7);

One important concept here, which only Marius touched upon, is recreating the table from scratch, instead of updating the existing one.这里只有 Marius 提到的一个重要概念是从头开始重新创建表格,而不是更新现有表格。 update generates undo and redo, which takes a lot of time and resources. update生成撤销和重做,这需要大量的时间和资源。 If you have indexes, updating them while you update the values in your table will add that much more overhead.如果您有索引,在更新表中的值时更新它们会增加更多的开销。 There is a lot of discussion, for example on AskTom, about this issue (and this suggestion - of creating a NEW table in such a case, instead of updating the existing one).有很多讨论,例如在 AskTom 上,关于这个问题(以及这个建议 - 在这种情况下创建一个新表,而不是更新现有表)。 You will see that they always remind you to make a note of indexes, triggers etc. that may exist on your table, so you can recreate them after you create the new table, drop the old one, and rename the new one to the old name.你会看到他们总是提醒你记下你表上可能存在的索引、触发器等,这样你就可以在创建新表后重新创建它们,删除旧表,并将新表重命名为旧表姓名。

For example: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:6407993912330例如: https : //asktom.oracle.com/pls/asktom/f?p=100 :11:0:: NO :: P11_QUESTION_ID : 6407993912330

Then, since you have a very large number of rows (in relational database terminology there are no "records"), it is best not to use regular expressions.然后,由于您有大量的行(在关系数据库术语中没有“记录”),最好不要使用正则表达式。 Michael offered a very efficient way to get the desired result using just standard string functions. Michael 提供了一种仅使用标准字符串函数即可获得所需结果的非常有效的方法。 Alternatively, if all your input strings are the same length, say ten characters (or if you don't really care to preserve the length - once you mask the "numbers" perhaps preserving their original length is irrelevant anyway) you may even do something like substr(source_num, 1, 6) || 'XXXX'或者,如果您所有的输入字符串长度相同,请说十个字符(或者如果您真的不关心保留长度 - 一旦您屏蔽了“数字”,也许保留它们的原始长度无论如何都无关紧要)您甚至可以做一些事情像substr(source_num, 1, 6) || 'XXXX' substr(source_num, 1, 6) || 'XXXX' - saving the repeated calls to length() and rpad() , one for each row in your table. substr(source_num, 1, 6) || 'XXXX' - 保存对length()rpad()的重复调用,表中的每一行都调用一次。

if your ultimate goal is to hide the data then Oracle redaction features available since 11gR2 is a very powerful and advanced feature but it is licensed under advanced security feature which will ensure that unwanted users will not be able to see unwanted data or see partial data.如果您的最终目标是隐藏数据,那么自 11gR2 以来可用的 Oracle 编校功能是一项非常强大且高级的功能,但它已根据高级安全功能获得许可,这将确保不需要的用户无法看到不需要的数据或部分数据。

Let me know if you need more details on the same.如果您需要更多详细信息,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM