CHAR_LENGTH

Description

CHAR_LENGTH is equivalent to CHARACTER_LENGTH and is used to return the number of characters in a string.

Syntax

CHAR_LENGTH(string|char|)

Parameter Description

  • string: The string expression whose character length is to be calculated.

Return Result

This function returns an integer representing the total number of characters in the input string.

Example

Example 1: Basic Usage

SELECT CHAR_LENGTH('Hello, World!');
+-------------------------------------+
| `CHAR_LENGTH`('Hello, World!') |
+-------------------------------------+
| 13                                  |
+-------------------------------------+

Example 2: Using with NULL Values

SELECT CHAR_LENGTH(NULL);
+--------------------------+
| `CHAR_LENGTH`(NULL) |
+--------------------------+
| null                     |
+--------------------------+

Example 3: Chinese Characters

 SELECT CHAR_LENGTH('中文');
+--------------------------+
| `CHARA_LENGTH`('中文') |
+--------------------------+
| 2                        |
+--------------------------+