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

How to generate a free certificate using openssl

1: What is openssl? What is its function? What is...

Share 13 basic syntax of Typescript

Table of contents 1. What is Ts 2. Basic Grammar ...

Detailed explanation of MySQL semi-synchronization

Table of contents Preface MySQL master-slave repl...

JavaScript modularity explained

Table of contents Preface: 1. Concept 2. The bene...

Do you know the weird things in Javascript?

Our veteran predecessors have written countless c...

Steps to install MySQL 8.0.23 under Centos7 (beginner level)

First, let me briefly introduce what MySQL is; In...

Semantics, writing, and best practices of link A

The semantics, writing style, and best practices ...

Mini Program to Implement Slider Effect

This article example shares the specific code for...

Analysis of the implementation principle of Vue instructions

Table of contents 1. Basic Use 2. Working Princip...

Vue routing relative path jump method

Table of contents Vue routing relative path jump ...

Detailed explanation of the difference between chown and chmod commands in Linux

In Linux system, both chmod and chown commands ca...

Pure CSS to achieve candle melting (water droplets) sample code

Achieve results Implementation ideas The melting ...

Detailed explanation of command to view log files in Linux environment

Table of contents Preface 1. cat command: 2. more...

MySQL InnoDB tablespace encryption example detailed explanation

Preface Starting from MySQL 5.7.11, MySQL support...