MySQL 如何在MySQL表的列上应用BIT_LENGTH()函数?
如果将BIT_LENGTH()函数应用于MySQL表的列,则它将返回存储在表的列中的字符串的位数。下面的示例将演示它的用法。
阅读更多:MySQL 教程
示例
假设我们想要从一个名为“Student”的表中找出存储在“Name”列和“Address”列中的字符串长度,则可以编写以下查询:
mysql> Select Name, Address, BIT_LENGTH(Name) As 'Name in Bits', BIT_LENGTH(Address) AS 'Address in Bits' from Student;
+---------+---------+--------------+-----------------+
| Name | Address | Name in Bits | Address in Bits |
+---------+---------+--------------+-----------------+
| Gaurav | Delhi | 48 | 40 |
| Aarav | Mumbai | 40 | 48 |
| Harshit | Delhi | 56 | 40 |
| Gaurav | Jaipur | 48 | 48 |
+---------+---------+--------------+-----------------+
4 rows in set (0.00 sec)
极客教程