CHAR_LENGTH()

Description

The CHAR_LENGTH function returns the length of the string str, measured in code points. A multibyte character counts as a single code point. This means that, for a string containing two 3-byte characters, CHAR_LENGTH returns 6, whereas CHAR_LENGTH returns 2.

Syntax

  1. > CHAR_LENGTH(str)

note

The alias for CHAR_LENGTH can also be lengthUTF8()

Arguments

ArgumentsDescription
strRequired. String you want to calculate.

Examples

  1. > drop table if exists t1;
  2. > create table t1(a varchar(255),b varchar(255));
  3. > insert into t1 values('nihao','你好');
  4. > select char_length(a), char_length(b) from t1;
  5. +---------------+---------------+
  6. | lengthutf8(a) | lengthutf8(b) |
  7. +---------------+---------------+
  8. | 5 | 2 |
  9. +---------------+---------------+