Batch replace part of the data of a field in Mysql (recommended)

Batch replace part of the data of a field in Mysql (recommended)

Batch replace part of the data of a field in MYSQL, the specific introduction is as follows:

1. Modify all text in the field containing the specified string

UPDATE tableA SET fieldB = replace(fieldB, 'aaa', 'bbb')
 example: update table set url= replace(url, 'aaa', 'bbb') [Batch change aaa in the url field to bbb]
  update table set url= REPLACE (url,'3','1.png') where condition;

2. Modification of general conditions:

update table set column='' where column is null 
Column: update `table` set `url`='0' where `url` is null

Knowledge point supplement: MySQL batch replaces part of the content of a field

Example

There is a data table person, the structure is as follows

id name urls
1 Zhang San xh.jpg
2 Li Si xh.jpg
3 Wang Wu 3.jpg

Requirement: Replace the xh in the urls field with the value of the id field

Statement:

UPDATE person SET urls = (REPLACE(urls,'xh',id));

Execution Result:

id name urls
1 Zhang San 1.jpg
2 Li Si 2.jpg
3 Wang Wu 3.jpg

Summarize

This is the end of this article about batch replacing part of the data in a field in MySQL. For more relevant MySQL batch replacement field content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • mysql replace part of the field content and mysql replace function replace()
  • Two query methods when the MySQL query field type is json
  • MySQL group by method for single word grouping sequence and multi-field grouping
  • Should nullable fields in MySQL be set to NULL or NOT NULL?
  • The difference between char, varchar and text field types in MySQL
  • Analysis of how to create a stored procedure in MySQL to add new fields to a data table
  • MySQL SQL statement to find duplicate data based on one or more fields
  • A brief understanding of MySQL storage field type query efficiency

<<:  Vue Getting Started with Weather Forecast

>>:  Ubuntu 20.04 Best Configuration Guide (Newbie Essential)

Recommend

mysql 8.0.19 winx64.zip installation tutorial

This article records the installation tutorial of...

An article to understand the advanced features of K8S

Table of contents K8S Advanced Features Advanced ...

Operate on two columns of data as new columns in sql

As shown below: select a1,a2,a1+a2 a,a1*a2 b,a1*1...

Vue data two-way binding implementation method

Table of contents 1. Introduction 2. Code Impleme...

Linux method example to view all information of the process

There is a task process on the server. When we us...

Try Docker+Nginx to deploy single page application method

From development to deployment, do it yourself Wh...

MySQL 8.0.12 installation and configuration graphic tutorial

Recorded the download and installation tutorial o...

Ubuntu regularly executes Python script example code

Original link: https://vien.tech/article/157 Pref...

Example of how to mosaic an image using js

This article mainly introduces an example of how ...

How to install php7 + nginx environment under centos6.6

This article describes how to install php7 + ngin...