replace()在mysql可以直接替換數據并顯示,如果你查替換數據并更新話我們需與update語句一起工作,下面我來給各位同學介紹操作方法,
最近更換了博客的代碼高亮插件,以前用的是SyntaxHighlighter,代碼格式如下:
- <pre class="brush: php; gutter: true">
- //代碼區
- ......
- </pre>現在換成了Crayon Syntax Highlighter:
- <pre class="lang_php decode_true">
- //代碼區
- ......
- </pre>
代碼高亮的區域不一樣,又有很多文章需要改,好吧,mysql肯定有替換功能函數,于是找了一下mysql的replace()函數資料.
replace()函數語法:update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
實例,代碼如下:
- mysql> SELECT REPLACE('m.survivalescaperooms.com', 'www', 'map');
- +----------------------------------------+
- | REPLACE('m.survivalescaperooms.com', 'www', 'map') |
- +----------------------------------------+
- | map.Vevb.com |
- +----------------------------------------+
- 1 row in set (0.00 sec)
因此一個函數可以replace()函數就十分方便的解決問題了,代碼如下:
- UPDATE wp_posts
- SET post_content = REPLACE(post_content, '<pre class="brush: php; gutter: true">', '<pre class="lang_php decode_true">');
我們還可以這樣用mysql replace,代碼如下:
replace into replace into table (id,name) values('1','aa'),('2','bb')
此語句的作用是向表table中插入兩條記錄.
新聞熱點
疑難解答