Home  >  Article  >  Database  >  sql server replace 批量替换数据库中指定字段内容

sql server replace 批量替换数据库中指定字段内容

WBOY
WBOYOriginal
2016-06-07 17:46:591335browse


function replace(title)
{
replace(title,'aaa','bbbb')
return(title)
}
bbb=replace(title)
update ..... set title='"&bbb&"'

access


Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("名.mdb")
Set rs = Server.Createobject("ADODB.Recordset")
sql="Select * from [表名]"
rs.open sql,conn,1,3
while not rs.eof
rs("字段名")=replace(rs("字段名"),"被替换的字符","替换为的字符")
rs.update
rs.movenext
wend
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

REPLACE ( 'string_e­xpression1' , 'string_e­xpression2' , 'string_e­xpression3' )
参数说明
'string_e­xpression1'
待搜索的字符串表达式。string_e­xpression1 可以是字符数据或二进制数据。
'string_e­xpression2'
待查找的字符串表达式。string_e­xpression2 可以是字符数据或二进制数据。
'string_e­xpression3'
替换用的字符串表达式。string_e­xpression3 可以是字符数据或二进制数据。

通俗理解即格式为:
Update 表名 SET 要替换的列=REPLACE(要替换的列,被替换的字符,替换后的字符)
示例SQL语句:
Update tableName SET columeName = REPLACE(columeName, 'a', 'b')

但是值得注意的一点是,SQL Server有 replace函数,可以直接使用;Access数据库的replace函数只能在Access环境下用,不能用在Jet SQL中,所以对ASP没用,在ASP中调用该函数会提示错误:表达式中 'REPLACE' 函数未定义。在Asp中可以写一个函数实现该功能

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常用函数Next article:导出sql语句