Skip to main content

Categories: String

MASK_SHOW_FIRST_N

Returns a masked version of a string with the first num_chars characters unmasked. By default, if you do not provide a value, the first four characters are shown.

Syntax

MASK_SHOW_FIRST_N(expression varchar [, num_chars int] [, uc_mask varchar] [, lc_mask varchar] [, num_mask varchar]) → varchar

  • expression: The string to mask.
  • num_chars (optional): The number of characters to unmask.
  • uc_mask (optional): Controls the mask character for upper case letters.
  • lc_mask (optional): Controls the mask character for lower case letters.
  • num_mask (optional): Controls the mask character for numbers.

Examples

MASK_SHOW_FIRST_N example
SELECT MASK_SHOW_FIRST_N('abcd-ABab-1234')
-- abcd-XXxx-nnnn
MASK_SHOW_FIRST_N example containing optional value
SELECT MASK_SHOW_FIRST_N('abcd-ABab-1234', 2)
-- abxx-XXxx-nnnn
MASK_SHOW_FIRST_N example containing optional arguments
SELECT MASK_SHOW_FIRST_N('Aa12-ABab-1234', 4, 'U', 'u', '#')
-- Aa12-UUuu-####
MASK_SHOW_FIRST_N example containing only the optional argument for lower case letters
SELECT MASK_SHOW_FIRST_N('abcd-ABCD-1234', 2, '', 'u', '')
-- abuu-XXXX-nnnn

Usage Notes

By default, upper case letters are converted to X, lower case letters are converted to x, and numbers are converted to n. You can override the characters used in the mask by supplying optional 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.