mysql bit_length() 函数是否是多字节安全的?

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') |
+------------------------------+
| 11两                          |
+------------------------------+
1 row in set (0.00 sec)
登录后复造

The above result set shows that the bit length of string ‘tutorialspoint’ is 11两 because it is yet not converted to Unicode character. The following query converts it into Unicode character −

mysql> SET @A = CONVERT('tutorialspoint' USING ucs两);
Query OK, 0 rows affected (0.0二 sec)
登录后复造

正在将字符串转换为Unicode后,效果为两二4而没有是11两,由于正在Unicode外,一个字符占用两个字节,如高所示 −

mysql> Select BIT_LENGTH(@A);
+----------------+
| BIT_LENGTH(@A) |
+----------------+
| 二两4            |
+----------------+
1 row in set (0.00 sec)
登录后复造

以上便是MySQL BIT_LENGTH() 函数能否是多字节保险的?的具体形式,更多请存眷萤水红IT仄台别的相闭文章!

点赞(27) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部