Home > Database > Mysql Tutorial > body text

Which function is synonymous with the MySQL LENGTH() function?

PHPz
Release: 2023-08-23 12:33:14
forward
1166 people have browsed it

MySQL LENGTH()函数的同义函数是哪个?

We know that MySQL's OCTET_LENGTH() function also measures the string length in "bytes", so it is a synonym for the MySQL LENGTH() function. The syntax of this function is OCTET_LENGTH(Str), where Str is the character string to be returned.

It also does not support multi-byte security like the LENGTH() function. For example, if a string contains four 2-byte characters, the OCTET_LENGTH() function will return 8. Demonstrated in the example below −

Example

mysql> Select OCTET_LENGTH('tutorialspoint');
+--------------------------------+
| OCTET_LENGTH('tutorialspoint') |
+--------------------------------+
|                             14 |
+--------------------------------+
1 row in set (0.00 sec)
Copy after login

The above result set shows that the string "tutorialspoint" has a length of 14 because it has not been converted to Unicode characters. The following query converts it to Unicode characters −

mysql> SET @A = CONVERT('tutorialspoint' USING ucs2);
Query OK, 0 rows affected (0.02 sec)
Copy after login

After converting the string to Unicode, the result is 28 instead of 14 because in Unicode, one character takes 2 bytes as shown below −

mysql> Select OCTET_LENGTH(@A);
+------------------+
| OCTET_LENGTH(@A) |
+------------------+
|               28 |
+------------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of Which function is synonymous with the MySQL LENGTH() function?. 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