Ted Ted - 6 months ago 35
SQL Question

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

Answer

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;
Comments