MySQL CHAR_LENGTH() Function
In MySQL, the CHAR_LENGTH()
function returns the length of the given string. CHAR_LENGTH()
returns number of characters in the given string. The CHARACTER_LENGTH()
function is an alias of the CHAR_LENGTH()
function.
CHAR_LENGTH()
Syntax
Here is the syntax of the MySQL CHAR_LENGTH()
function:
CHAR_LENGTH(string)
Parameters
string
- Required. The string to be calculated.
Return value
The CHAR_LENGTH()
function returns number of characters in the given string. It will return NULL
if the string
parameter is NULL
.
CHAR_LENGTH()
Examples
To return the length of Hello
, use the following statement:
SELECT CHAR_LENGTH('Hello');
+----------------------+
| CHAR_LENGTH('Hello') |
+----------------------+
| 5 |
+----------------------+
You can use Chinese characters like 你好
:
SELECT CHAR_LENGTH('你好');
+-----------------------+
| CHAR_LENGTH('你好') |
+-----------------------+
| 2 |
+-----------------------+
Note that it returned 2
. Because there are only 2
characters in this string: 你好
.