Just like LENGTH() function, MySQL BIT_LENGTH() function is not a multi-byte safe function. As we know that the difference of the result between multi-byte safe functions, like CHAR_LENGTH() or CHARACTER_LENGTH(), and BIT_LENGTH() function especially relevant for Unicode, in which most of the characters are encoded in two bytes or relevant for UTF-8 where the number of bytes varies. It is demonstrated in the example below ?
Example
mysql> Select BIT_LENGTH('tutorialspoint');
+------------------------------+
| BIT_LENGTH('tutorialspoint') |
+------------------------------+
| 112 |
+------------------------------+
1 row in set (0.00 sec)
登錄后復(fù)制
The above result set shows that the bit length of string ‘tutorialspoint’ is 112 because it is yet not converted to Unicode character. The following query converts it into Unicode character −
mysql> SET @A = CONVERT('tutorialspoint' USING ucs2);
Query OK, 0 rows affected (0.02 sec)
登錄后復(fù)制
在將字符串轉(zhuǎn)換為Unicode后,結(jié)果為224而不是112,因?yàn)樵赨nicode中,一個(gè)字符占用2個(gè)字節(jié),如下所示 −
mysql> Select BIT_LENGTH(@A); +----------------+ | BIT_LENGTH(@A) | +----------------+ | 224 | +----------------+ 1 row in set (0.00 sec)
登錄后復(fù)制
以上就是MySQL BIT_LENGTH() 函數(shù)是否是多字節(jié)安全的?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!






