Home >Database >Mysql Tutorial >How to use the MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-08-29 22:25:071329browse

如何使用 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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:MySQL information sourceNext article:MySQL information source