---
title: mask function
description: Learn the syntax of the mask function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/mask
---

# `mask` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) 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](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-function-invocation.md#named-parameter-invocation).

## Syntax

```
mask(str [, upperChar [, lowerChar [, digitChar [, otherChar ] ] ] ] )
```

## Arguments

* `str`: A `STRING` expression.
* `upperChar`: A single character `STRING` literal used to substitute upper case characters. The default is `'X'`. If `upperChar` is `NULL`, upper case characters remain unmasked.
* `lowerChar`: A single character `STRING` literal used to substitute lower case characters. The default is `'x'`. If `lowerChar` is `NULL`, lower case characters remain unmasked.
* `digitChar`: A single character `STRING` literal used to substitute digits. The default is `'n'`. If `digitChar` is `NULL`, digits remain unmasked.
* `otherChar`: A single character `STRING` literal used to substitute any other character. The default is `NULL`, which leaves these characters unmasked.

## Returns

A STRING.

## Common error conditions

* [DATATYPE\_MISMATCH.INPUT\_SIZE\_NOT\_ONE](https://docs.databricks.com/aws/en/error-messages/datatype-mismatch-error-class.md#input_size_not_one)
* [DATATYPE\_MISMATCH.NON\_FOLDABLE\_INPUT](https://docs.databricks.com/aws/en/error-messages/datatype-mismatch-error-class.md#non_foldable_input)

## Examples

```sql
> 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-&^ % 서울 Ä

-- Replacement characters must be single characters
> SELECT mask('AbCD123-@$#', 'Qa');
  Error: DATATYPE_MISMATCH.INPUT_SIZE_NOT_ONE
```

## Related functions

* [`crc32` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/crc32.md)
* [`hash` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/hash.md)
* [`sha` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/sha.md)
* [`sha1` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/sha1.md)
* [`sha2` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/sha2.md)
