mask
Description
Syntax:
VARCHAR mask(VARCHAR str, [, VARCHAR upper[, VARCHAR lower[, VARCHAR number]]])
This function returns a masked version of str
. By default, upper case letters are converted to "X", lower case letters are converted to "x", and numbers are converted to "n". For example, the returned result of mask("abcd-EFGH-8765-4321") will be xxxx-XXXX-nnnn-nnnn. You can override the characters used in the mask by providing additional arguments: the second argument controls the mask character for upper case letters, the third argument for lower case letters, and the fourth argument for numbers. For example, the returned result of mask("abcd-EFGH-8765-4321", "U", "l", "#") will be llll-UUUU-####-####.
Example
// table test
+-----------+
| name |
+-----------+
| abc123EFG |
| NULL |
| 456AbCdEf |
+-----------+
mysql> select mask(name) from test;
+--------------+
| mask(`name`) |
+--------------+
| xxxnnnXXX |
| NULL |
| nnnXxXxXx |
+--------------+
mysql> select mask(name, '*', '#', '$') from test;
+-----------------------------+
| mask(`name`, '*', '#', '$') |
+-----------------------------+
| ###$$$*** |
| NULL |
| $$$*#*#*# |
+-----------------------------+
Keywords
mask