Search code examples
sqloracle-databasedata-masking

Data masking in Oracle SQL select statement


Without using PL/SQL, is it possible to do data masking in SELECT statement?

For example:

(AS-IS) SELECT 'this is a string' from DUAL;

this is a string

(TO-BE) SELECT 'this is a string' from DUAL;

xxxx xx x xxxxxx


Solution

  • REGEXP_REPLACE can do this:

    SELECT REGEXP_REPLACE('this is a string', '\w', 'x') FROM DUAL;
    

    This replaces all non-whitespace characters with an x. To replace letters only, try this:

    SELECT REGEXP_REPLACE('this is a string', '[A-Za-z]', 'x') FROM DUAL;