Convert char from a blob to a number in a SQL statement and save it in a different field _mysql

Source: Internet
Author: User

This requirement is a table structure that itself is designed to

But now you need to save the data in the 17, 18, 193 fields in the BLOB as a number in a new three field outside the Blob Gem1 Gem2 Gem3.

You can do this by using the following SQL statement:
1, add three fields:

Copy Code code as follows:

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 the BLOB
Update Equipmentinfo Set Gem1=conv (substr (HEX (Equipmentblob), 17,2), 16,10), Gem2=conv (substr (HEX), 19,2), 16,10), Gem3=conv (substr (HEX (Equipmentblob), 21,2), 16,10);
Description
HEX (Equipmentblob) converts equipmentblob to a 16-in-system string
SUBSTR (Str,beginidx,num) intercepts the string of STR from the BEGINIDX and intercepts the length of num
Conv (n,from_base,to_base) N is the data to be converted, From_base is the original, and the To_base is the target system.

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.