MySQL partial replacement SQL statement sharing

Source: Internet
Author: User

Replace the welcom to Cdb_pms table subject field with Welcome

Copy CodeThe code is as follows:
UPDATE ' Cdb_pms '
SET ' Subject ' = REPLACE (' Subject ', ' Welcome to ', ' welcome ')
WHERE INSTR (' Subject ', ' Welcome to ') > 0


Replace the message field of the Cdb_posts table with "viewthread.php?tid=3989" replaced by "viewthread.php?tid=16546"

Copy CodeThe code is as follows:
UPDATE ' cdb_posts '
SET ' message ' = REPLACE (' message ', ' viewthread.php?tid=3989 ', ' viewthread.php?tid=16546 ')
WHERE INSTR (' message ', ' viewthread.php?tid=3989 ') > 0;


Delete all the spaces

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = TRIM (' Pro_pub_time ')


Remove all ' [' or '] ' or '. ' The character

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = REPLACE (' pro_pub_time ', ' [', ') WHERE INSTR (' pro_pub_time ', ' [') > 0
UPDATE ' es_product ' SET ' pro_pub_time ' = REPLACE (' Pro_pub_time ', '] ', ') WHERE INSTR (' pro_pub_time ', '] ') > 0
UPDATE ' es_product ' SET ' pro_pub_time ' = REPLACE (' Pro_pub_time ', '. ', '-') WHERE INSTR (' pro_pub_time ', '. ') > 0


Replace all English '-' with Chinese '-'

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = REPLACE (' pro_pub_time ', '-', '-') WHERE INSTR (' pro_pub_time ', '-') > 0


Replace all the years with '-'

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = REPLACE (' Pro_pub_time ', ' Year ', '-') WHERE INSTR (' Pro_pub_time ', ' year ') > 0
UPDATE ' es_product ' SET ' pro_pub_time ' = REPLACE (' pro_pub_time ', ' month ', '-') WHERE INSTR (' Pro_pub_time ', ' month ') > 0


Replace all ' 2005-04-' of this type with ' 2005-04-01 '

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = CONCAT (' pro_pub_time ', ' ") WHERE substring_index (' pro_pub_time ', '-',-1) = ' ' and length ' (' pro_pub_time ') > 0 and Length (' Pro_pub_time ') > 5


Replace All ' 2005-' This type with ' 2005-01-01 '

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = CONCAT (' pro_pub_time ', ' 01-01 ') WHERE INSTR (' pro_pub_time ', '-') > 0 and Lengt H (' pro_pub_time ') = 5


Add all '-', but the number of bits less than 8 to ' 01 '

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = CONCAT (' pro_pub_time ', ' -01 ') WHERE INSTR (' pro_pub_time ', '-') > 0 and LENGTH ( ' Pro_pub_time ') < 8


Change All ' 2005 ' to ' 2005-01-01 '

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = CONCAT (' pro_pub_time ', ' -01-01 ') WHERE INSTR (' pro_pub_time ', '-') = 0 and LENGTH (' Pro_pub_time ') = 4


Finally, all ' 2005-01-01 ' is formatted as ' January 2005 '

Copy CodeThe code is as follows:
UPDATE ' es_product ' SET ' pro_pub_time ' = date_format (' pro_pub_time ', '%y year%m month ') WHERE INSTR (' pro_pub_time ', '-') > 0

MySQL partial replacement SQL statement sharing

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.