我想把这段中文批量成英文,但不会写Sql批量修改语句,怎么写?

如.我想把“中国”改成china 怎么批量更换.
是想要批量替换啊.
update 表名 set title=replace(title,'中国','china')
这样的不行的。
我要的是批量替换啊,我们假设现在不考虑text类型.update 表名 set title=replace(title,'中国','china') 这个只能一张表一张表的打开,然后字段一一替换,那样太麻烦了,我想有什么方法可以批量进行替换。

白衣非少年
浏览 259回答 3
3回答

紫衣仙女

update 表名 set title=replace(title,'中国','china')为什么不行, 错误还是怎么, 说的一点不清楚, 如果错误提示是什么, 你的数据结构也不清楚, 没法回答你下面过程是数据库中所有表中含有某一值替换成新值,你参考一下, 就可以替换数据库中固定某字段,下面的固定字符串了If exists (select * from sysobjects where name = 'replaceString' and xtype = 'P' )Drop procedure replaceStringGoCreate procedure replaceString (@tableName varchar(255),@oldStr varchar(255), @newStr varchar(255))asDeclare @Sql varchar(1024)Declare @tableId varchar(20)declare @columnName varchar(20)declare @columnCursor cursordeclare @colNameCursor cursorIf len(@TableName) > 0BeginSelect @Sql = 'Declare TabCursor cursor read_only for select name ,id from sysobjects where name ='+@TableNameExec(@Sql)EndelseDeclare 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 TabCursorfetch TabCursor into @tableName,@tableIdwhile @@Fetch_status = 0BeginSelect @Sql = 'Declare ColumnCursor cursor scroll read_only for select name from syscolumns where id='+@tableId+' and xtype=167 'Exec(@sql)open ColumnCursorfetch ColumnCursor into @columnNamewhile @@Fetch_status = 0BeginSelect @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 @columnNameEndclose columnCursordeallocate columnCursorfetch Next From TabCursor into @tableName,@tableIdEndclose tabCursordeallocate tabCursor

萧十郎

sql="select * from [表]"rs.open sql,conn,1,3if rs.eof thenwhile not rs.eofrs("title")=replace(rs("title"),'中国','china')rs.updaters.movenextwendend ifrs.close

MYYA

如果是TEXT 型的字段必须要先转换为字符型才能用REPLACE函数
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server