mask
function
Applies to: Databricks SQL Databricks Runtime 12.2 LTS and above
Returns a masked version of the input str
.
In Databricks SQL and Databricks Runtime 13.3 LTS and above this function supports named parameter invocation.
Syntax
mask(str [, upperChar [, lowerChar [, digitChar [, otherChar ] ] ] ] )
Arguments
str
: ASTRING
expression.upperChar
: A single characterSTRING
literal used to substitute upper case characters. The default is'X'
. IfupperChar
isNULL
, upper case characters remain unmasked.lowerChar
: A single characterSTRING
literal used to substitute lower case characters. The default is'x'
. IflowerChar
isNULL
, lower case characters remain unmasked.digitChar
: A single characterSTRING
literal used to substitute digits. The default is'n'
. IfdigitChar
isNULL
, digits remain unmasked.otherChar
: A single characterSTRING
literal used to substitute any other character. The default isNULL
, which leaves these characters unmasked.
Returns
A STRING.
Examples
> SELECT mask('AaBb123-&^ % 서울 Ä');
XxXxnnn-&^ % 서울 X
> SELECT mask('AaBb123-&^ % 서울 Ä', 'Z', 'z', '9', 'X');
ZzZz999XXXXXXXXXZ
> SELECT mask('AaBb123-&^ % 서울 Ä', lowerchar => 'z', otherchar => 'X');
AzBz123XXXXXXXXXÄ
> SELECT mask('AaBb123-&^ % 서울 Ä', otherchar => '?');
AaBb123?????????Ä
> SELECT mask('AaBb123-&^ % 서울 Ä', NULL, NULL, NULL, NULL);
AaBb123-&^ % 서울 Ä