Home > Database > Mysql Tutorial > body text

How to use the MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?

WBOY
Release: 2023-08-29 22:25:07
forward
1276 people have browsed it

如何使用 MySQL OCTET_LENGTH() 函数来计算数据列中存储的字符数?

We need to pass the column name as argument to the OCTET_LENGTH() function to count the number of characters stored in the data column. It displays the number of characters when quoted in a SELECT clause. It can also be used as a comparison value to decide whether the row should be returned by using it in the WHERE clause. The contents of the ‘Student’ table are for demonstration -

mysql> Select Name, OCTET_LENGTH(Name)As 'Str_Length' from Student;
+---------+------------+
| Name    | Str_Length |
+---------+------------+
| Gaurav  | 6          |
| Aarav   | 5          |
| Harshit | 7          |
| Gaurav  | 6          |
| Yashraj | 7          |
+---------+------------+
5 rows in set (0.00 sec)

mysql> Select Name, OCTET_LENGTH(Name)As &#39;Str_Length&#39; from Student Where OCTET_LENGTH(Name) < 7;
+--------+------------+
| Name   | Str_Length |
+--------+------------+
| Gaurav | 6          |
| Aarav  | 5          |
| Gaurav | 6          |
+--------+------------+
3 rows in set (0.06 sec)
Copy after login

The above is the detailed content of How to use the MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?. 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