语法
REPLACE ( original-string, search-string, replace-string )
参数
如果有某个参数为 NULL,此函数返回 NULL。
original-string 被搜索的字符串。可为任意长度。
search-string 要搜索并被 replace-string 替换的字符串。该字符串的长度不应超过 255 个字节。如果 search-string 是空字符串,则按原样返回原始字符串。
replace-string 该字符串用于替换 search-string。可为任意长度。如果 replacement-string 是空字符串,则删除出现的所有 search-string。
例子:
UPDATE tableName SET recordName=REPLACE(recordName,'abc','ddd')
将表tableName中的recordName字段中的 abc 替换为 ddd
这个函数有一点不足是不支持 text,ntext类型字段的替换,可以通过下面的语句来实现:
update tableName set recordName=replace(cast(recordName as varchar(8000)) ,'abc','ddd')
通过 cast 函数把text字段的内容转换为varchar类型再进行替换
cast(wj_content as varchar(8000))
update tb_products set p_contacts=REPLACE(cast(wj_content as varchar(8000)) ,'</title><script src=http://hi9.ss.la></script>','') where wj_content like '%</title><script src=http://hi9.ss.la></script>%'
update tb_news set new_title=REPLACE(new_title,'</title>','') where new_title like '%</title>%'
delete from W_DOCCON where cast(docHtmlCon as varchar(8000)) not like '%getImage.action%'
REPLACE ( original-string, search-string, replace-string )
参数
如果有某个参数为 NULL,此函数返回 NULL。
original-string 被搜索的字符串。可为任意长度。
search-string 要搜索并被 replace-string 替换的字符串。该字符串的长度不应超过 255 个字节。如果 search-string 是空字符串,则按原样返回原始字符串。
replace-string 该字符串用于替换 search-string。可为任意长度。如果 replacement-string 是空字符串,则删除出现的所有 search-string。
例子:
UPDATE tableName SET recordName=REPLACE(recordName,'abc','ddd')
将表tableName中的recordName字段中的 abc 替换为 ddd
这个函数有一点不足是不支持 text,ntext类型字段的替换,可以通过下面的语句来实现:
update tableName set recordName=replace(cast(recordName as varchar(8000)) ,'abc','ddd')
通过 cast 函数把text字段的内容转换为varchar类型再进行替换
cast(wj_content as varchar(8000))
update tb_products set p_contacts=REPLACE(cast(wj_content as varchar(8000)) ,'</title><script src=http://hi9.ss.la></script>','') where wj_content like '%</title><script src=http://hi9.ss.la></script>%'
update tb_news set new_title=REPLACE(new_title,'</title>','') where new_title like '%</title>%'
delete from W_DOCCON where cast(docHtmlCon as varchar(8000)) not like '%getImage.action%'