CHARACTER_LENGTH or CHAR_LENGTH

The CHARACTER_LENGTH or CHAR_LENGTH function returns the length of a string expression.

Read syntax diagramSkip visual syntax diagramCHARACTER_LENGTHCHAR_LENGTH(expression)

See LENGTH for a similar function.

expression
An expression that returns a value of any built-in numeric or string data type. A numeric argument is cast to a character string before evaluating the function. For more information about converting numeric to a character string, see VARCHAR.

The result of the function is a large integer. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

If expression is a character string or graphic string, the result is the number of characters in the argument (not the number of bytes). A single character is either an SBCS, DBCS, or multiple-byte character. If expression is a binary string, the result is the number of bytes in the argument. The length of strings includes trailing blanks or hexadecimal zeroes. The length of a varying-length string is the actual length, not the maximum length.

Example

  • Assume that NAME is a VARCHAR(128) column, encoded in Unicode UTF-8, that contains the value 'Jürgen'.
      SELECT CHARACTER_LENGTH(NAME), LENGTH(NAME)
        FROM T1
        WHERE NAME = 'Jürgen'
    Returns the value 6 for CHARACTER_LENGTH and 7 for LENGTH.