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

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 互联网粒子

论公司运营 复杂问题需要系统思维 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