Computer >> Computer tutorials >  >> Programming >> MySQL

What is the purpose of using MySQL CHAR_LENGTH() function? Which function is the synonym of it?


MySQL CHAR_LENGTH() is used to retrieve the length of a specified string. This function will simply count the number of characters and ignores whether the characters are of single-byte or multi-byte. MySQL CHARACTER_LENGTH() function is a synonym of it. The syntax of these functions are as follows −

Syntax of CHAR_LENGTH

CHAR_LENGTH (Str)

Here, Str is the string whose length is to be retrieved.

Syntax of CHARACTER_LENGTH

CHARACTER_LENGTH (Str)

Here, Str is the string whose length is to be retrieved.

Example

mysql> Select CHAR_LENGTH('tutorialspoint');
+-------------------------------+
| CHAR_LENGTH('tutorialspoint') |
+-------------------------------+
|                            14 |
+-------------------------------+
1 row in set (0.03 sec)

mysql> Select CHARACTER_LENGTH('tutorialspoint');
+------------------------------------+
| CHARACTER_LENGTH('tutorialspoint') |
+------------------------------------+
|                                 14 |
+------------------------------------+
1 row in set (0.00 sec)