sql 字符串替换处理函数
create function dbo.regexreplace
(
@source varchar(5000), --原字符串
@regexp varchar(1000), --正则表达式
@replace varchar(1000), --替换值
@globalreplace bit = 0, --是否是全局替换
@ignorecase bit = 0 --是否忽略大小?
)
returns varchar(1000) as
begin
declare @hr integer
declare @objregexp integer
declare @result varchar(5000)exec @hr = sp_oacreate 'vbscript.regexp', @objregexp output
if @hr <> 0 begin
exec @hr = sp_oadestroy @objregexp
return null
end
exec @hr = sp_oasetproperty @objregexp, 'pattern', @regexp
if @hr <> 0 begin
exec @hr = sp_oadestroy @objregexp
return null
end
exec @hr = sp_oasetproperty @objregexp, 'global', @globalreplace
if @hr <> 0 begin
exec @hr = sp_oadestroy @objregexp
return null
end
exec @hr = sp_oasetproperty @objregexp, 'ignorecase', @ignorecase
if @hr <> 0 begin
exec @hr = sp_oadestroy @objregexp
return null
end
exec @hr = sp_oamethod @objregexp, 'replace', @result output, @source, @replace
if @hr <> 0 begin
exec @hr = sp_oadestroy @objregexp
return null
end
exec @hr = sp_oadestroy @objregexp
if @hr <> 0 begin
return null
endreturn @result
end
go调用方法:select dbo.regexreplace('aa6bb4cc7c','d+','aa',1,1)
输出结果:aaaabbaaccaac
mysql教程字符串替换函数
replace 函数即可批量改变某字段中的某一段字符串。
查 mysql 里的 replace 函数
update `xxx` set `a` = replace(`a` , '要替换的' , '替换为的') where xxx
===php教程china.com===============================================================
update `xxx` set `a` = replace(`a` , '要替换的' , '替换为的') where xxx
update `music` set `file` = replace(`file` , '' , 'ddd') where id<10
update music set file=replace(file, '', 'def') where id < 10 ;
===mysql.com===============================================================
用mysql的replace函数替换字符串
比如你要将 表 tb1里面的 f1字段的abc替换为def
update tb1 set f1=replace(f1, 'abc', 'def');
replace(str,from_str,to_str)
在字符串 str 中所有出现的字符串 from_str 均被 to_str替换,然后返回这个字符串:
mysql> select replace('www.111com.net', 'w', 'ww');
-> 'wwwwww.mysql.com'
这个函数是多字节安全的。
mysql替换函数二
在数据转换的时候须要用到mysql的replace函数,这里基本介绍一下!
比如你要将 表 tb1里面的 f1字段的abc替换为def
update tb1 set f1=replace(f1, 'abc', 'def');
replace(str,from_str,to_str)
在字符串 str 中所有出现的字符串 from_str 均被 to_str替换,然后返回这个字符串:
mysql> select replace('www.mysql.com', 'w', 'ww');
-> 'wwwwww.mysql.com'
这个函数是多字节安全的。示例:
update `dede_addonarticle` set body = replace ( body,
'',
'' );
update `dede_addonarticle` set body = replace ( body,
'',
'' );
update `dede_addonarticle` set body = replace ( body,
'',
'' );
update `dede_archives` set title= replace ( title,
'大洋新闻 - ',
'' );
update `dede_addonarticle` set body = replace ( body,
'../../../../../../',
'http://mb.111com.net' );mysql replace
用法1.replace intoreplace into table (id,name) values('1','aa'),('2','bb')
此语句的作用是向表table中插入两条记录。
2.replace(object, search,replace)
把object中出现search的全部替换为replaceselect replace('www.111com.net','w','ww')--->www www.111com.net相关文章
精彩推荐
![]()
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载![]()
火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载![]()
荒野乱斗测试服 安卓版v61.10.3
下载![]()
荒野乱斗彩虹服 安卓版v61.10.3
下载
下载寒霜启示录 安卓版v1.25.10
模拟经营 寒霜启示录 安卓版v1.25.10寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
下载末日城堡免广告版 安卓最新版v0.7.1
模拟经营 末日城堡免广告版 安卓最新版v0.7.1末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
下载甜蜜人生模拟器 最新版v1.4.5
模拟经营 甜蜜人生模拟器 最新版v1.4.5甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
下载武器锻造师内置功能菜单 v10.4
模拟经营 武器锻造师内置功能菜单 v10.4武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
下载开放空间overfield 安卓版v1.0.5
模拟经营 开放空间overfield 安卓版v1.0.5开放空间Overfield是一款箱庭养成经营手游,让你在广阔