Binary type operation for MySQL

Source: Internet
Author: User
Tags uuid

Sample data table:

CREATE TABLE Test_bin (bin_id BINARY (+) not NULL) Engine=innodb;

Insert data (content is a 32-bit UUID string value):

Insert into Test_bin (bin_id) VALUES (Unhex (' fa34e10293cb42848573a4e39937f479 ')), insert into Test_bin (bin_id) VALUES ( Unhex (?)); or INSERT into Test_bin (bin_id) VALUES (x ' fa34e10293cb42848573a4e39937f479 ');

Query data:

SELECT HEX (bin_id) as bin_id from Test_bin; SELECT HEX (bin_id) as bin_id from test_bin WHERE bin_id = Unhex (' fa34e10293cb42848573a4e39937f479 '); SELECT HEX (bin_id) as bin_id from test_bin WHERE bin_id = Unhex (?); SELECT HEX (bin_id) as bin_id from Test_bin WHERE bin_id = x ' fa34e10293cb42848573a4e39937f479 '; query result: Bin_ ID--------------------------fa34e10293cb42848573a4e39937f479


Note: use the MySQL built-in UUID () to create a function that returns a binary (16) type of UUID value

Create function uu_id () RETURNS binary (+) RETURN Unhex (REPLACE (UUID (), '-', ')), or create function uu_id () RETURNS binary ( ) RETURN Unhex (REVERSE (REPLACE (UUID (), '-', ')); use: INSERT into Test_bin (bin_id) VALUES (uu_id ());


Binary type operation for MySQL

Related Article

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.