Home > Database > Mysql Tutorial > body text

How to get the length of a specified string in MySQL?

PHPz
Release: 2023-08-30 10:17:09
forward
1198 people have browsed it

How to get the length of a specified string in MySQL?

The CHAR_LENGTH() or CHARACTER_LENGTH() string function in MySQL is used to retrieve the length of a specified string. This function only counts the number of characters, regardless of whether the characters are 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)
Copy after login

The above is the detailed content of How to get the length of a specified string in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!