Retrieve Length of Specified String in MySQL



CHAR_LENGTH() or CHARACTER_LENGTH() string functions in MySQL are 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.

Example

mysql> Select CHAR_LENGTH('New Delhi');
+--------------------------+
| CHAR_LENGTH('New Delhi') |
+--------------------------+
| 9                        |
+--------------------------+
1 row in set (0.00 sec)

mysql> Select CHAR_LENGTH('NewDelhi');
+-------------------------+
| CHAR_LENGTH('NewDelhi') |
+-------------------------+
| 8                       |
+-------------------------+
1 row in set (0.00 sec)

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

mysql> Select CHARACTER_LENGTH('New Delhi');
+-------------------------------+
| CHARACTER_LENGTH('New Delhi') |
+-------------------------------+
| 9                             |
+-------------------------------+
1 row in set (0.00 sec)
Updated on: 2020-06-20T07:47:20+05:30

100 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements