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相关文章
精彩推荐
![]()
敢达决战官方正版 安卓版v6.7.9
下载![]()
敢达决战 安卓版v6.7.9
下载![]()
像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载![]()
要塞英雄 安卓版v33.20.0-39082670-Android
下载
下载梦想城镇vivo最新版本 安卓版v12.0.1
模拟经营 梦想城镇vivo最新版本 安卓版v12.0.1梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
下载怦然心动的瞬间 安卓版v1.0
模拟经营 怦然心动的瞬间 安卓版v1.0怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
下载曼尼汉堡店游戏 安卓版v1.0.3
模拟经营 曼尼汉堡店游戏 安卓版v1.0.3曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
下载现代总统模拟器去广告版 安卓版v1.0.46
模拟经营 现代总统模拟器去广告版 安卓版v1.0.46现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
下载现代总统模拟器付费完整版 安卓版v1.0.46
模拟经营 现代总统模拟器付费完整版 安卓版v1.0.46现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级