惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 互联网粒子

论公司运营 复杂问题需要系统思维 Razor视图引擎-基础语法 项目管理-项目进度偏差分析 无线互联的三大机会 IT公司的情.理.法.文管理 康盛被腾讯“招安” - 互联网粒子 - 博客园 在WIN7系统IIS7下配置PHP5运行环境 基于JSON缓存的多国语言的实现 IIS7中启用JS的压缩 用户个性化推荐 IE6下的JQUERY_FCK兼容问题 - 互联网粒子 - 博客园 软件需求全景 .NET中使用WINDOWS API参数定义 如何下载安装和破解VS2010 windows下面的管理命令 如何查询Sql Server 2005补丁版本号 javascript模板机制 javascript上实现动态参数
数据库字符串内容批量更新
互联网粒子 · 2010-04-13 · via 博客园 - 互联网粒子

数据库经常会遇到需要把一些内容白批量替换的问题,有时是因为存数据时没有编码,有时是因为有些不良的信息,要直接替换。

整理了下如何用SQL语句来替换:

替换指定列内容语句

update [t_test] set [detail] =  REPLACE([detail],'打到XXX','新字符串')

注意,这个语句是不能替换ntext的,除了ntext类型的字符类型是可以全部替换

如果要替换ntext类型字段是需要进行类型转换

update [t_test] set [detail] = replace(convert(varchar(4000), [detail]),'打到XXX','新字符串'') where id<4

写一小段SQL来执行完成整个数据表的替换

declare @ptr varbinary(16)
declare @artId int
declare @Position int,@len int
set @len = datalength('XXXA')
declare wux_Cursor scroll Cursor
for
select textptr([detail]),id from t_test
for read only
open wux_Cursor
fetch next from wux_Cursor into @ptr,@artId
while @@fetch_status=0
begin
select @Position=patindex('%打到XXX%',[detail]) from t_test where id=@artId
while @Position>0
begin
set @Position=@Position-1
updatetext [t_test].[detail] @ptr @Position @len 'XXXA'
select @Position=patindex('%打到XXX%',detail) from t_test where id=@artId
end
fetch next from wux_Cursor into @ptr,@artId
end
close wux_cursor
deallocate wux_cursor
go