我们需要将列名作为OCTET_LENGTH()函数的参数传递,以计算存储在数据列中的字符数。在SELECT子句中引用时,它显示字符数。它也可以用作比较值,以决定是否应通过在WHERE子句中使用该行来返回该行。“学生”表的内容用于演示它-
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 'Str_Length' from Student Where OCTET_LENGTH(Name) < 7; +--------+------------+ | Name | Str_Length | +--------+------------+ | Gaurav | 6 | | Aarav | 5 | | Gaurav | 6 | +--------+------------+ 3 rows in set (0.06 sec)