Home  >  Article  >  Database  >  mysql和MSSQL字符替换函数

mysql和MSSQL字符替换函数

WBOY
WBOYOriginal
2016-06-07 17:48:33926browse

文章简单的介绍了关于字符替换了sql语句,很简单我们都只要用到update与replace来进行实现替换哦,有城要的朋友参考一下

MSSQL替换语句:update 表名 set 字段名=replace(cast(字段名 as varchar(8000)),'abc.com','123.com')

例如:

 代码如下 复制代码
update PE_Article set Content=replace(cast(Content as varchar(8000)),'http://111cn.net/','http://www.hzhuti.com/')

其中PE_Article 为表名  Content为字段名 为要替换的内容  为替换后的内容。

下面看 replace替换语句,其实也等

replace('www.mysql.com',   'w',   'ww'); 

replace(object,search,replace)
把object中出现search的全部替换为replace
replace('www.163.com','w','Ww')--->WwWwWw.163.com
例:把表table中的name字段中的aa替换为bb
update table set name=replace(name,'aa','bb')

 代码如下 复制代码

update `表名` set body=replace(body,'"upfile','"/upfile') WHERE body like '%src="upfile%' and cityid in(1176,1177,1178,1179,1181)

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
Previous article:sql where条件语句用法Next article:SQL创建视图实例