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

Detailed explanation of the usage of image tags in HTML

In HTML, the <img> tag is used to define an...

Web lesson plans, lesson plans for beginners

Teaching Topics Web page Applicable grade Second ...

Solve the problem of spring boot + jar packaging deployment tomcat 404 error

1. Spring boot does not support jsp jar package, ...

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

Detailed explanation of Linux zabbix agent deployment and configuration methods

1. Install zabbix-agent on web01 Deploy zabbix wa...

JavaScript code to achieve a simple calendar effect

This article shares the specific code for JavaScr...

iFrame is a great way to use it as a popup layer to cover the background

I have been working on a project recently - Budou ...

This article will show you what Vite does to the browser's request

Table of contents Working principle: What does th...

Pricing table implemented with CSS3

Result: Implementation Code html <div id="...

Detailed explanation of MySQL 8.0 atomic DDL syntax

Table of contents 01 Introduction to Atomic DDL 0...

How to deploy SpringBoot project using Dockerfile

1. Create a SpringBooot project and package it in...

Solve the problem that PhpStorm fails to connect to VirtualBox

Problem description: When phpstorm's SFTP hos...

Solution to the conflict between two tabs navigation in HTML

Let's start with a description of the problem...