登录
首页 >  数据库 >  MySQL

MySQL BIT_LENGTH() 函数是否是多字节安全的?

来源:tutorialspoint

时间:2023-08-25 18:05:47 280浏览 收藏

golang学习网今天将给大家带来《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') |
+------------------------------+
| 112                          |
+------------------------------+
1 row in set (0.00 sec)

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)

在将字符串转换为Unicode后,结果为224而不是112,因为在Unicode中,一个字符占用2个字节,如下所示 −

mysql> Select BIT_LENGTH(@A);
+----------------+
| BIT_LENGTH(@A) |
+----------------+
| 224            |
+----------------+
1 row in set (0.00 sec)

今天关于《MySQL BIT_LENGTH() 函数是否是多字节安全的?》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>