Home >Database >Mysql Tutorial >mysql 如何替换某字段值的部分内容

mysql 如何替换某字段值的部分内容

WBOY
WBOYOriginal
2016-06-01 09:57:061343browse

要替换某一个字段中的部分内容,可以用update 语句: 

<code class="language-sql">UPDATE 表名 SET 字段名= REPLACE( 替换前的字段值, '替换前关键字', '替换后关键字' ) WHERE 字段名 REGEXP "替换前的字段值"; </code>

 

比如替换标题里面的产品价格就是用这个方法

<code class="language-sql">UPDATE dede_archives SET title= REPLACE( title, 155, 170 ); 
UPDATE dede_archives SET title= REPLACE( title, 180, 230 ); 
UPDATE dede_archives SET title= REPLACE( title, 270, 350 ); 
UPDATE dede_archives SET title= REPLACE( title, 210, 170 ); 
UPDATE dede_archives SET title= REPLACE( title, 155, 170 ); </code>

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