欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

sqlserver replace函數(shù) 批量替換數(shù)據(jù)庫中指定字段內(nèi)指定字符串參考方法

 更新時(shí)間:2010年05月07日 18:39:02   作者:  
SQL Server有 replace函數(shù),可以直接使用;Access數(shù)據(jù)庫的replace函數(shù)只能在Access環(huán)境下用,不能用在Jet SQL中,所以對ASP沒用,在ASP中調(diào)用該函數(shù)會(huì)提示錯(cuò)誤.
語法
REPLACE ( 'string_e­xpression1' , 'string_e­xpression2' , 'string_e­xpression3' )
參數(shù)說明
'string_e­xpression1'
待搜索的字符串表達(dá)式。string_e­xpression1 可以是字符數(shù)據(jù)或二進(jìn)制數(shù)據(jù)。
'string_e­xpression2'
待查找的字符串表達(dá)式。string_e­xpression2 可以是字符數(shù)據(jù)或二進(jìn)制數(shù)據(jù)。
'string_e­xpression3'
替換用的字符串表達(dá)式。string_e­xpression3 可以是字符數(shù)據(jù)或二進(jìn)制數(shù)據(jù)。

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

但是值得注意的一點(diǎn)是,SQL Server有 replace函數(shù),可以直接使用;Access數(shù)據(jù)庫的replace函數(shù)只能在Access環(huán)境下用,不能用在Jet SQL中,所以對ASP沒用,在ASP中調(diào)用該函數(shù)會(huì)提示錯(cuò)誤:表達(dá)式中 'REPLACE' 函數(shù)未定義。在Asp中可以寫一個(gè)函數(shù)實(shí)現(xiàn)該功能。
示例函數(shù):
復(fù)制代碼 代碼如下:

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

ASP+access批量替換指定字符參考代碼:
復(fù)制代碼 代碼如下:

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("數(shù)據(jù)庫名.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
%>

相關(guān)文章

最新評論