【www.gdgbn.com--php与数据库】


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

asp教程 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中可以写一个函数实现该功能

本文来源:http://www.gdgbn.com/jiaocheng/24517/