mysql> create table t(a bit());
Query OK, rows affected (0.04 sec) mysql> insert into t select b'';
Query OK, row affected (0.18 sec)
Records: Duplicates: Warnings: mysql> select * from t;
+------+
| a |
+------+
| |
+------+
row in set (0.00 sec) mysql> select hex(a) from t;
+--------+
| hex(a) |
+--------+
| |
+--------+
row in set (0.00 sec)

Bit-field values can be written using b'value' or 0bvalue notation. value is a binary value written using zeros and ones.

Bit-field notation is convenient for specifying values to be assigned to BIT columns:

mysql> CREATE TABLE t (b BIT(8));
mysql> INSERT INTO t SET b = b'11111111';
mysql> INSERT INTO t SET b = b'1010';
mysql> INSERT INTO t SET b = b'0101';

Bit values are returned as binary values. To display them in printable form, add 0 or use a conversion function such as BIN(). High-order 0 bits are not displayed in the converted value.

mysql> SELECT b+0, BIN(b+0), OCT(b+0), HEX(b+0) FROM t;
+------+----------+----------+----------+
| b+0 | BIN(b+0) | OCT(b+0) | HEX(b+0) |
+------+----------+----------+----------+
| 255 | 11111111 | 377 | FF |
| 10 | 1010 | 12 | A |
| 5 | 101 | 5 | 5 |
+------+----------+----------+----------+

Bit values assigned to user variables are treated as binary strings. To assign a bit value as a number to a user variable, use CAST() or +0:

mysql> SET @v1 = 0b1000001;
mysql> SET @v2 = CAST(0b1000001 AS UNSIGNED), @v3 = 0b1000001+0;
mysql> SELECT @v1, @v2, @v3;
+------+------+------+
| @v1 | @v2 | @v3 |
+------+------+------+
| A | 65 | 65 |
+------+------+------+

Bit data type的更多相关文章

  1. PHP 笔记一(systax/variables/echo/print/Data Type)

    PHP stands for "Hypertext Preprocessor" ,it is a server scripting language. What Can PHP D ...

  2. JAVA 1.2(原生数据类型 Primitive Data Type)

    1. Java的数据类型分为2类 >> 原生数据类型(primitive data type) >> 引用数据类型(reference data type) 3. 常量和变量 ...

  3. salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema ...

  4. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

    刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data ...

  5. XML Data Type Methods(一)

    XML Data Type Methods(一) /*XML Data Type Methods: 1.The query('XQuery') method retrieves(vt.检索,重新得到) ...

  6. include pointers as a primitive data type

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Many modern programming languages in ...

  7. Extended Data Type Properties [AX 2012]

    Extended Data Type Properties [AX 2012] This topic has not yet been rated - Rate this topic Updated: ...

  8. org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String

    org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.Strin ...

  9. Linux C double linked for any data type

    /************************************************************************** * Linux C double linked ...

  10. SQL Server error "Xml data type is not supported in distributed queries" and workaround for it

    Recently while working with data migration,got an error while running a following query where Server ...

随机推荐

  1. Js 获取 本周、本月起始时间

    涉及到显示本月或本周相关信息,又不想让php去判断,只好直接用js去计算,麻烦了好一阵,还是老老实实的看了下js的日期函数.现总结一下: //计算本周起始日期,并以 Y-m-d 形式返回.    fu ...

  2. sql如果存在就修改不存在就新增

    FROM 表名 WHERE 条件) UPDATE 表名 SET 字段=值 WHERE 条件 ELSE INSERT INTO 表名(字段) VALUES(值) 真实使用举例: from [UserRu ...

  3. Java反射的理解

    反射的作用:   1.运行时检查类的结构 2.运行时更改类的字段值 3.调用类的方法   准备知识:   Class类:虚拟机为每一个对象保存的一份对象所属类的清单: static Class for ...

  4. spm使用之五修改spm自带文档主题模板

    spm自带的文档的主题模板, 其文件在C:\Documents and Settings\Administrator\.spm\themes 目录下, 有个叫做cmd 文件夹的. 其实 cmd这个文件 ...

  5. Eclipse插件卸载

            以前搞过安卓,重装系统后,安卓损坏了,每次还会提示那个窗口很烦人.       使用Eclipse自带的卸载插件功能即可,Help->About Eclipse->Inst ...

  6. List Of All Machine Learning Sorted By Citation

    List Of All Machine Learning Sorted By Citation With > 300 citations 2013-10-10 See Citation Anal ...

  7. jquery deferred

    http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html http:// ...

  8. 用POLL的方式,没有跑出结果来,立此存照

    咦,这些内容,和我以前看内核时的东东,对应起来了.. SELECT,POLL,EPOLL,非阻塞,异步之类的... 但我没有调出来.回家有空了可以看看,不用再敲打代码啦... #!/usr/bin/e ...

  9. 【HDU2222】Keywords Search(AC自动机)

    Problem Description In the modern time, Search engine came into the life of everybody like Google, B ...

  10. asp.net关于Cookie跨域(域名)的问题

    Cookie是一个伟大的发明,它允许Web开发者保留他们的用户的登录状态.但是当你的站点有一个以上的域名时就会出现问题了.在Cookie规范上 说,一个cookie只能用于一个域名,不能够发给其它的域 ...