Use an SQL statement to extract the char in blob and convert it to a number and save it in another field _ MySQL

Source: Internet
Author: User
Use an SQL statement to extract the char in blob and convert it to a number and save it to another field bitsCN.com.

This requires a table structure, designed

But now we need to save the data in the 17, 18, and 19 fields in blob as numbers to the three new fields Gem1 Gem2 Gem3 added outside blob.

The following SQL statement can be used:
1. add three fields:

Alter table EquipmentInfo add Gem1 tinyint unsigned default 0;
Alter table EquipmentInfo add Gem2 tinyint unsigned default 0;
Alter table EquipmentInfo add Gem3 tinyint unsigned default 0;

2. use the following command to copy the data in blob
Update EquipmentInfo set Gem1 = conv (substr (HEX (EquipmentBlob), 17,2), 16,10), Gem2 = conv (substr (HEX (EquipmentBlob), 19,2), 16,10 ), gem3 = conv (substr (HEX (EquipmentBlob), 21,2), 16,10 );
Note:
HEX (EquipmentBlob) converts EquipmentBlob into a HEX string.
Substr (str, beginIdx, num) truncates str from the string starting with beginIdx. the truncation length is num.
Conv (N, from_base, to_base) N is the data to be converted, from_base is the original base, and to_base is the target base.

BitsCN.com

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.