How to implement partial contents of replacement Fields in mysql
This article will explain in detail how mysql implements part of the replacement field. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
[mysql]replace usage
1.replace into
replace into table (id,name) values('1','aa'),('2','bb')
This statement inserts 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')
Data is not inserted if identical values exist
2.replace(object,search,replace)
Replace all search entries in object with replace
select replace('www.163.com','w','Ww')--->WwWwWw.163.com
Example: Replace aa with bb in the name field of table
update table set name=replace(name,'aa','bb')
UPDATE updates part of a field
Now I have a record with a field called "abcdefg" and I just want to change the c in that field to C. How do you write update statements?
update table name set field 1 = replace(field 1,'c',' C')
Knowledge Point Extension:
mysql replace function replace() implements mysql to replace a string in a specified field
How to replace strings with mysql:
The replace function in mysql directly replaces a specific string in a field in mysql database, no longer needs to write its own function to replace it, which is very convenient to use. mysql replace()
UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str%'
Description:
table_name --The name of the table
field_name --field name
from_str --String to replace
to_str --The string to replace
For example:
mysql> SELECT REPLACE('www.lvtao.net', 'www', 'http://www');
-> 'https://www.lvtao.net'
This function is multibyte safe, meaning you don't have to worry about whether it's Chinese or English characters.
About "mysql how to replace part of the field" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.