当前位置:数据库 > MySQL >>

MySQL之替换字符串函数replace()的使用

最近更换了博客的代码高亮插件,以前用的是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.zzzyk.com', 'www', 'map');
+----------------------------------------+
| REPLACE('www.zzzyk.com', 'www', 'map') |
+----------------------------------------+
| map.zzzyk.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中插入两条记录。

补充:数据库,mysql教程 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,