您的位置:程序门 -> ms-sql server -> 基础类



求一sql语句


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求一sql语句
发表于:2007-05-24 23:00:32 楼主
假设我一个表table里有两个字段id、content,其中可能有n条数据中的content字段中含有字符“aaa”,我现在想修改content中含有“aaa”的所有数据,使它们里面的“aaa”改成“bbb”

请问这个能不能实现?如果能实现是不是很毫资源
发表于:2007-05-24 23:02:531楼 得分:0
update   表   set   content=replace(content, 'aaa ', 'bbb ')
发表于:2007-05-24 23:03:102楼 得分:0
update   tbname   set   content=replace(content, 'aaa ', 'bbb ')
发表于:2007-05-24 23:05:243楼 得分:0
update   [table]   set   content= 'bbb '   where   content= 'aaa '--如果是等的意思
update   [table]   set   content=replace(content, 'bbb ', 'aaa '   where   content   like   '%aaa% '
--如果是包含的意思
看数据量,一般不会
发表于:2007-05-24 23:07:484楼 得分:0
sorry
update   [table]   set   content=replace(content, 'aaa ', 'bbb ')   where   content   like   '%aaa% '
用like   的效率会低很多
发表于:2007-05-24 23:09:315楼 得分:0
update   tbname   set   content=replace(content, 'aaa ', 'bbb ')
where   charindex( 'aaa ',content)> 0
发表于:2007-05-28 00:01:166楼 得分:0
这个好像有点问题,譬如我content字段中含有“美女   美女123”,我现在只是想严格替换“美女”,而如果有“**美女**”,这样的则不要替换,请问可以实现吗?
发表于:2007-05-28 10:37:157楼 得分:0
sql语句中支不支持正则表达式啊?
发表于:2007-05-28 14:14:018楼 得分:0
sql语句中支不支持正则表达式啊?

支持!
发表于:2007-05-28 14:33:579楼 得分:0
这个好像有点问题,譬如我content字段中含有“美女   美女123”,我现在只是想严格替换“美女”,而如果有“**美女**”,这样的则不要替换,请问可以实现吗?
--------------------------------------------------------------------------
检测   1.美女是不是在首部,charindex( '美女 ',content)=1   and   content   like   '美女   % '

2.在中间   content   like   '%   美女   % '

3.在后面   charindex( '女美 ',reverse(content))=1   and   content   like   '%   美女 '


快速检索

最新资讯
热门点击