Skip to content

Instantly share code, notes, and snippets.

@Jonathan-49
Last active April 7, 2024 12:29
Show Gist options
  • Save Jonathan-49/72e1b615e3e395e2b4cf14b4051b1b6d to your computer and use it in GitHub Desktop.
Save Jonathan-49/72e1b615e3e395e2b4cf14b4051b1b6d to your computer and use it in GitHub Desktop.
Obscure_emailaddress
-- https://www.rpgpgm.com/2024/01/sql-repeat-scalar-function.html
-- IBM Db2 for i
SELECT EMAIL_ADDRESS,
SUBSTR(EMAIL_ADDRESS, 1, 1) ||
REGEXP_REPLACE(LOWER(SUBSTR(EMAIL_ADDRESS, 2,
(LOCATE_IN_STRING(EMAIL_ADDRESS, '@') - 2))),
'[a-z]|[0-9]|[._]', 'x')
|| SUBSTR(EMAIL_ADDRESS, LOCATE_IN_STRING(EMAIL_ADDRESS, '@'))
FROM TESTFILE;
-- An alternative method
SELECT EMAIL_ADDRESS,
SUBSTR( EMAIL_ADDRESS, 1, 1) ||
repeat('x', LOCATE_IN_STRING( EMAIL_ADDRESS, '@') -2) ||
SUBSTR( EMAIL_ADDRESS, LOCATE_IN_STRING(EMAIL_ADDRESS, '@'))
FROM TESTFILE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment