We have one requirement to mask a particular table column using a Oracle function which gives persistent masked output string.
- We tried Oracle Hash Function but it does not give String type return value.
- We tried Oracle Random function (dbms_random.string) but it does not give Persistent output string.
I read on internet that this is called deterministic masking. But we do not want to use Oracle Enterprise Manager; however we require a direct Oracle function.
Please suggest.
This problem is easily solved in 12c with the function STANDARD_HASH.
The solution in previous versions is only slightly more complicated. Build a simple wrapper around DBMS_CRYPTO that acts just like STANDARD_HASH:
You may need to logon with SYS and grant your user access to DBMS_CRYPTO to make the function work:
Create a public synonym, grant it to everyone, and it works exactly the same way.
Here is a simple example of using the function:
But updating large amounts of data can be slow. It may be faster to create a new table, drop the old one, rename the new one, etc. And the hash value may be larger than the column size, it may be necessary to
alter table some_table modify column1 varchar2(40 byte);
It amazes me how many products and tools there are to do such a simple thing.
If you looking something like mask the production data to move it into non-prod for integration testing. Below the "user defined" function would be helpful to you. This function will work only 10G and above.
You can use dbms_crpyto package of oracle , first you need to convert varchar2 type to raw then mask the data according to the hash value.
In Oracle 12C dbms_redact.add_policy is available. It can be used to get the masked value in the select query itself.