How does MySql insert and query binary data?

Source: Internet
Author: User
Tags mysql insert

How does MySql insert and query binary data mysql binary Mysql: bit-type query and insert mysql has a field type of bit. 1. How to insert it? It must be inserted: You can use the B 'value' symbol to write the field value. Value is a binary value written as 0 and 1.

mysql> create table an_bit (id bit(8));Query OK, 0 rows affected (0.00 sec)mysql> insert into an_bit values (11);Query OK, 1 row affected (0.00 sec)

 

Although it can be inserted, the actual inserted value is 11 (decimal), not 3 (decimal ).
mysql> insert into an_bit values (b’11′);Query OK, 1 row affected (0.00 sec)

 

This is the correct insert method. The inserted value is 3 (decimal) 2. How can I query it?
Mysql> select * from an_bit; + -- + | id | + -- + this is incorrect, and mysql> select id + 0 from an_bit is invisible; + -- + | id + 0 | + -- + | 11 | 3 | + -- + this is correct. You can see the decimal value. Mysql> select bin (id + 0) from an_bit; + ---- + | bin (id + 0) | + ---- + | 1011 | 11 | + ---- + This is the binary value mysql> select oct (id + 0) from an_bit; + ---- + | oct (id + 0) | + ---- + | 13 | 3 | + ---- + This is the octal value of mysql> select hex (id + 0) from an_bit; + ---- + | hex (id + 0) | + ---- + | B | 3 | + ---- + THIS IS THE hexadecimal value.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.