Home >Database >Mysql Tutorial >How to Replace 'updates' with 'news' in MySQL URLs?

How to Replace 'updates' with 'news' in MySQL URLs?

DDD
DDDOriginal
2024-12-20 09:09:09857browse

How to Replace

MySQL String Replacement

This question addresses the need to modify specific text within a MySQL database column. The task involves replacing instances of the word "updates" with "news" in URLs stored in a column.

To achieve this, a MySQL script can be employed to execute a REPLACE function on the affected column. The script suggested in the provided answer is designed to accomplish the desired modification:

UPDATE your_table
SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/news/')
WHERE your_field LIKE '%articles/updates/%'

This script effectively searches for occurrences of the string "articles/updates/" within the "your_field" column and replaces them with "articles/news/". The WHERE clause ensures that only rows containing the specified string are modified.

For instance, a URL originally stored as "http://www.example.com/articles/updates/43" will be transformed into "http://www.example.com/articles/news/43". This change is reflected across all rows in the table that match the search criteria.

The above is the detailed content of How to Replace 'updates' with 'news' in MySQL URLs?. 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