3 回答

TA贡献1839条经验 获得超15个赞
update 表名 set title=replace(title,'中国','china')
为什么不行, 错误还是怎么, 说的一点不清楚, 如果错误提示是什么, 你的数据结构也不清楚, 没法回答你
下面过程是数据库中所有表中含有某一值替换成新值,你参考一下, 就可以替换数据库中固定某字段,下面的固定字符串了
If exists (select * from sysobjects where name = 'replaceString' and xtype = 'P' )
Drop procedure replaceString
Go
Create procedure replaceString (@tableName varchar(255),@oldStr varchar(255), @newStr varchar(255))
as
Declare @Sql varchar(1024)
Declare @tableId varchar(20)
declare @columnName varchar(20)
declare @columnCursor cursor
declare @colNameCursor cursor
If len(@TableName) > 0
Begin
Select @Sql = 'Declare TabCursor cursor read_only for select name ,id from sysobjects where name ='+@TableName
Exec(@Sql)
End
else
Declare TabCursor cursor read_only for select name ,id from sysobjects where xtype='u'
--set tabCursor = cursor scroll read_only for select name ,id from sysobjects where xtype='u'
open TabCursor
fetch TabCursor into @tableName,@tableId
while @@Fetch_status = 0
Begin
Select @Sql = 'Declare ColumnCursor cursor scroll read_only for select name from syscolumns where id='+@tableId+' and xtype=167 '
Exec(@sql)
open ColumnCursor
fetch ColumnCursor into @columnName
while @@Fetch_status = 0
Begin
Select @Sql = 'update '+@tableName+' set '+@columnName+' = (replace('+@columnName+','+char(39)+@oldStr+char(39)+','+char(39)+@newStr+char(39)+')) where charindex('+char(39)+@oldStr+char(39)+','+@columnName+')>0 '
Exec(@sql)
fetch Next From ColumnCursor into @columnName
End
close columnCursor
deallocate columnCursor
fetch Next From TabCursor into @tableName,@tableId
End
close tabCursor
deallocate tabCursor

TA贡献1815条经验 获得超13个赞
sql="select * from [表]"
rs.open sql,conn,1,3
if rs.eof then
while not rs.eof
rs("title")=replace(rs("title"),'中国','china')
rs.update
rs.movenext
wend
end if
rs.close
- 3 回答
- 0 关注
- 194 浏览
添加回答
举报