Data masking in Oracle SQL select statement

Ted picture Ted · Aug 18, 2013 · Viewed 15.1k times · Source

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

Ed Gibbs picture Ed Gibbs · Aug 18, 2013

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;