Add the prefix 00 and navicatmysql to a field in Mysql in Navicat.

Source: Internet
Author: User

Add the prefix 00 and navicatmysql to a field in Mysql in Navicat.

For the first time, I hope you will pay more attention to it.

In my case, if the content of the varchar field in a table in Navicat is less than 5 characters long, add '0' before the content. If the field content is 101, I will change it to 00101;

There are two difficulties: 1. determine the length of the field content (I do not know enough) 2. Add a prefix to the field content;

The previous error SQL is:

Update base_sf set diy_code = '00' + diy_code

Where pk in (select pk from base_sf where LENGTH (diy_code) = 3)

In this way, diy_code in Navicat is regarded as a numerical value, so it has never been successful.

The correct SQL statement is:

Update base_sf set diy_code = concat ('0', diy_code)

Where pk in (select * from (select pk from base_sf where LENGTH (diy_code) = 4) tmp)

 

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.