Skip to main content

MASK_FIRST_N

Description​

The MASK_FIRST_N function is mainly used to mask the first N bytes of data to protect sensitive information, and is commonly used in data anonymization scenarios. Its behavior is to replace a uppercase letter with X, a lowercase letter with x, and a number with n in the first N bytes.

Syntax​

MASK_FIRST_N( <str> [, <n> ])

Parameters​

ParameterDescription
<str>String that need to be masked
<n>Optional Parameter, limit data masking to only the first N bytes, default to masking the entire string

Return Value​

Returns a string after masking uppercase character, lowercase character and lnumeric character in first N bytes. Special cases:

  • If any Parameter is NULL, NULL will be returned.
  • Non-alphabetic and non-numeric characters will do not masking

Examples​

select mask_first_n("1234-5678-8765-4321", 4);
+----------------------------------------+
| mask_first_n('1234-5678-8765-4321', 4) |
+----------------------------------------+
| nnnn-5678-8765-4321 |
+----------------------------------------+
select mask_first_n("1234-5678-8765-4321", null);
+-------------------------------------------+
| mask_first_n('1234-5678-8765-4321', NULL) |
+-------------------------------------------+
| NULL |
+-------------------------------------------+