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. Python: 设计模式 之 工厂模式例(1)

    #!/usr/bin/env python #coding=utf-8 # # 工厂模式一例 # 版权所有 2014 yao_yu (http://blog.csdn.net/yao_yu_126) ...

  2. JQUERY 插件开发——LAZYLOADIMG(预加载和延迟加载图片)

    开发背景 本插件开发是近期写的最后一个插件了,接下来我想把最近研究的redis最为一个系列阐述下.当然Jquery插件开发是我个人爱好,我不会停止,在将来的开发中我会继续完善,当然也会坚持写这个系列的 ...

  3. 精心挑选的12款优秀 jQuery Ajax 分页插件和教程

    在这篇文章中,我为大家收集了12个基于 jQuery 框架的 Ajax 分页插件,这些插件都提供了详细的使用教程和演示.Ajax 技术的出现使得 Web 项目的用户体验有了极大的提高,如今借助优秀的  ...

  4. [BZOJ 1081] [SCOI2005] 超级格雷码 【找规律】

    题目链接:BZOJ - 1081 备注:此题BZOJ上貌似没有 spj ,要把一般顺序的每个格雷码倒着输出...比如 0102 输出为 2010 题目分析 就是按照 Gray 码的生成方法写前几个出来 ...

  5. uva 11136 - Hoax or what

    用两个优先队列来实现,因为队列只能从一头出去: 所以维护一个数组,来标记这个队列的已经出列而另外一个队列没有出列的元素: 到时候再把他们删了就行: #include<cstdio> #in ...

  6. vs2010编译curl为static库及测试

    1,编译curl为static库 用vs2010打开: curl-7.32.0\vs\vc6\vc6curl.dsw 选择LIB Release生成libcurl静态库: curl-7.32.0\vs ...

  7. HTML5区域范围文本框实例页面

    CSS代码: input { font-size: 14px; font-weight: bold; } input[type=range]:before { content: attr(min); ...

  8. LeetCode解题报告:Linked List Cycle && Linked List Cycle II

    LeetCode解题报告:Linked List Cycle && Linked List Cycle II 1题目 Linked List Cycle Given a linked ...

  9. Android应用--新浪微博客户端新特性滚动视图和启动界面实现

    新浪微博客户端新特性滚动视图和启动界面实现 2013年8月20日新浪微博客户端开发之启动界面实现 前言: 使用过新浪微博客户端的童鞋都清楚,客户端每一次升级之后第一次启动界面就会有新特性的介绍,用户通 ...

  10. git reset到之前的某一个commit或者恢复之前删除的某一个分支

    一.使用了git reset之后,想要找回某一个commit 1.git log -g  这个命令只能显示少部分的commit 推荐使用git reflog 找到想要恢复的那个commit的hash, ...