comcoma
comcoma

Reputation: 11

How to change specific part of the text in MySQL for selected column?

I have a table news, it has a column description. In the descriptions' column I use <p> tags. I want all the <p> tags to be changed into <p itemprop="description"> . How can I do it?

Upvotes: 0

Views: 115

Answers (2)

ajreal
ajreal

Reputation: 47321

select replace(description, '<p>', '<p itemprop="description">') from news

It is not recommended. My suggestion is to pull the original data from MySQL, then perform the string replacement in the UI or frontend scripts.

Upvotes: 0

Memduh
Memduh

Reputation: 866

Try this;

UPDATE `news`
SET `description` = REPLACE(description, '<p>', '<p itemprop="description">')

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html

Upvotes: 1

Related Questions