当将BIT_LENGTH()函数应用于MySQL表的列时,它将返回存储在表的列中的字符串的位数。以下示例将对其进行演示。
假设从表“ Student”中我们想要找到存储在“名称”和“地址”列中的字符串的长度,那么我们可以编写以下查询:
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)