最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
sql 字符串替换处理函数
时间:2022-11-14 23:37:47 编辑:袖梨 来源:一聚教程网
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相关文章
热门栏目
php教程
php入门 php安全 php安装 php常用代码 php高级应用asp.net教程
基础入门 .Net开发 C语言 VB.Net语言 WebService手机开发
安卓教程 ios7教程 Windows Phone Windows Mobile 手机常见问题css教程
CSS入门 常用代码 经典案例 样式布局 高级应用网页制作
设计基础 Dreamweaver Frontpage js教程 XNL/XSLT办公数码
word excel powerpoint 金山WPS 电脑新手jsp教程
Application与Applet J2EE/EJB/服务器 J2ME开发 Java基础 Java技巧及代码