Home > Database > Mysql Tutorial > How to replace fields in mysql

How to replace fields in mysql

青灯夜游
Release: 2022-01-04 16:43:27
Original
9157 people have browsed it

In mysql, you can use the "UPDATE" statement and the REPLACE() function to replace fields. The syntax "UPDATE table name set field name = REPLACE(field name,'content to be replaced','replaced with content');".

How to replace fields in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

MySql field replacement for all and part of the field

Syntax:

UPDATE 表名 set 字段名 = REPLACE(字段名,'要替换的内容','替换成的内容');
Copy after login

can also be written as:

UPDATE 表名 set 字段名 = REPLACE(字段名,fromStr,toStr);
Copy after login

(1) Replace all

Replace all and send the replaced and to be replaced

UPDATE user_bag SET cover_url = REPLACE(cover_url, ‘http://static.zpnb.com/768.jpg’,‘http://static.bddvip.com/zpnb412.png’) WHERE id = 1
Copy after login

(2) Partial replacement

For example, I want to For http://static.zpnb.com/768.jpg in the image path, replace http with https. Just fill in http and https, and do not reverse the order.

UPDATE XXX SET item_example_img = REPLACE (item_example_img,‘http’,‘https’)
Copy after login

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to replace fields in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template