MySQL之替換字串函數replace()的使用

來源:互聯網
上載者:User

最近更換了部落格的代碼高亮外掛程式,以前用的是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('www.111cn.net', 'www', 'map');
+----------------------------------------+
| REPLACE('www.111cn.net', 'www', 'map') |
+----------------------------------------+
| map.111cn.net |
+----------------------------------------+

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中插入兩條記錄。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.