mysql replace part of the field content and mysql replace function replace()

mysql replace part of the field content and mysql replace function replace()

[mysql] replace usage (replace part of the content of a field)

[mysql] replace usage

1. replace into

replace into table (id,name) values('1','aa'),('2','bb')
The purpose of this statement is to insert two records into the table. If the primary key id is 1 or 2 and does not exist, it is equivalent to
insert into table (id,name) values('1','aa'),('2','bb')
If the same value exists, the data will not be inserted.

2.replace(object,search,replace)

Replace all occurrences of search in object with replace
select replace('www.163.com','w','Ww')--->WwWwWw.163.com
Example: Replace aa in the name field in the table table with bb
update table set name=replace(name,'aa','bb')

3.UPDATE updates part of the content in a field

Now there is a record with a field "abcdefg". Now I just want to change the c in the field to C. How should I write the update statement?

update table name set field1 = replace(field1,'c','C')

Knowledge point expansion:

mysql replace function replace() implements mysql to replace the string in the specified field

MySQL replace string implementation method:

The replace function in MySQL directly replaces a specific string in a field in the MySQL database. You no longer need to write your own function to replace it, which is very convenient to use. mysql replace function replace()

UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str%'

illustrate:

table_name - the name of the table

field_name —— field name

from_str - the string to be replaced

to_str —— the string to be replaced

For example:

mysql> SELECT REPLACE('www.lvtao.net', 'www', 'http://www');

-> 'https://www.lvtao.net'

This function is multi-byte safe, which means you don't have to consider whether it is Chinese characters or English characters.

Summarize

This is the end of this article about mysql replace field part and mysql replace function replace(). For more relevant mysql replace field content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Batch replace part of the data of a field in Mysql (recommended)
  • 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

<<:  This article takes you into the world of js data types and data structures

>>:  Summary of ten Linux command aliases that can improve efficiency

Recommend

Solution to the problem of session failure caused by nginx reverse proxy

A colleague asked for help: the login to the back...

How to deploy springcloud project with Docker

Table of contents Docker image download Start mys...

How to install Jenkins using Docker

Table of contents 1. Pull the image 2. Create a l...

How to implement a lucky wheel game in WeChat applet

I mainly introduce how to develop a lucky wheel g...

CSS3 flexible box flex to achieve three-column layout

As the title says: The height is known, the width...

What magical uses does CSS filter have

background Basic Concepts CSS filter property app...

Mysql string interception and obtaining data in the specified string

Preface: I encountered a requirement to extract s...

Solution for VMware Workstation Pro not running on Windows

After the National Day holiday, did any of you fi...

A complete tutorial on installing Ubuntu 20.04 using VMware virtual machine

Ubuntu is a relatively popular Linux desktop syst...

Zen coding for editplus example code description

For example, he enters: XML/HTML Code div#page>...

A "classic" pitfall of MySQL UPDATE statement

Table of contents 1. Problematic SQL statements S...

CSS flexible layout FLEX, media query and mobile click event implementation

flex layout Definition: The element of Flex layou...

MySQL 5.7.21 winx64 installation and configuration method graphic tutorial

This article summarizes the notes for installing ...

Analysis of the principles of docker containers

Table of contents 01 What is the essence of a con...

IE8 Developer Tools Menu Explanation

<br />This article has briefly explained the...