Home>Article>Database> How to replace fields in mysql

How to replace fields in mysql

青灯夜游
青灯夜游 Original
2022-01-04 16:43:27 9046browse

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(字段名,'要替换的内容','替换成的内容');

can also be written as:

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

(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

(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’)

[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!

Statement:
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