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