The mysql section replaces the sql statement share

  • 2020-05-12 06:18:33
  • OfStack

Replace Welcom to in the subject field of the cdb_pms table with welcome

 
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 "instead of" viewthread.php? tid = 16546"
 
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 Spaces
 
UPDATE `es_product` SET `pro_pub_time` = TRIM(`pro_pub_time`) 

Delete all characters containing '[' or ']' or '.
 
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 words with Chinese '-' with English '-'
 
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ' - ','-') WHERE INSTR(`pro_pub_time`,' - ') > 0 

Replace all the years with '-'
 
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ' years ','-') WHERE INSTR(`pro_pub_time`,' years ') > 0 
UPDATE `es_product` SET `pro_pub_time` = REPLACE(`pro_pub_time`, ' month ','-') WHERE INSTR(`pro_pub_time`,' month ') > 0 

Replace all '2005-04-' with '2005-04-01'
 
UPDATE `es_product` SET `pro_pub_time` = CONCAT( `pro_pub_time`, '01') WHERE SUBSTRING_INDEX( `pro_pub_time`, '-', -1) = '' AND LENGTH(`pro_pub_time`) > 0 AND LENGTH(`pro_pub_time`) > 5 

Replace all '2005-' types with '2005-01-01'
 
UPDATE `es_product` SET `pro_pub_time` = CONCAT( `pro_pub_time`, '01-01') WHERE INSTR(`pro_pub_time`,'-') > 0 AND LENGTH(`pro_pub_time`) = 5 

I'm going to append everything that's full of '-' but has less than 8 digits to '-01'
 
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'
 
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, format all '2005-01-01' to 'January 2005'
 
UPDATE `cdb_posts` 
SET `message`= REPLACE(`message`, 'viewthread.php?tid=3989', 'viewthread.php?tid=16546') 
WHERE INSTR(`message`,'viewthread.php?tid=3989') > 0 ; 
0


Related articles: