sql字符替换与利用sql存储过程替换

php中文网
发布: 2016-06-07 17:47:51
原创
2096人浏览过

如果你在替换数据库的指定字符串或字符,我们需要利用sql字符替换,但是对于超大容量的数据替换我们可能要用到sql存储过程替换 物,因为存储过程效率高于我们自己写的替换函数哦。

如果你在替换的指定字符串或字符,我们需要利用sql字符替换,但是对于超大容量的数据替换我们可能要用到sql替换 物,因为存储过程效率高于我们自己写的替换函数哦。

update 数据表 set 字段=replace(字段,'.','')

下面看一款查询结果字符替换

--select * from sjz_dlfzb

--select replace (substring(tbrq,2,len(tbrq)-2),'$','-') from sjz_dlfzb

update sjz_dlfzb set tbrq=replace (substring(tbrq,2,len(tbrq)-2),'$','-')

 update sjz_hpzb set wdm=replace (substring(wdm,2,len(wdm)-2),'$','-') where hp_id !='130121010001'

美图云修
美图云修

商业级AI影像处理工具

美图云修 61
查看详情 美图云修


update sjz_hpzb set dxslx=replace (substring(dxslx,2,len(dxslx)-2),'$','-')


select * from sjz_nslzb

update sjz_nslzb set tbrq=replace (substring(tbrq,2,len(tbrq)),'$','-') where nsl_id='130131030061'

select * from sjz_nslzb where nsl_id='130131030061'

select * from sjz_nslzb where nsl_id='130132030033'
update sjz_nslzb set tbrq=replace (tbrq,'$','-') where nsl_id='130132030033'
sjz_xpzb

update sjz_xpzb set wd=replace (substring(wd,2,len(wd)),'$','-')


利用存储过程替换字符

create   table   hello(id   int   identity(1,1),content   text)  
  insert   into   hello  
  select   '
'  
  union   all   select   '
'  
   
  --定义替换/删除的字符串  
  declare   @s_str   varchar(8000),@d_str   varchar(8000)  
  select   @s_str='http://localhost/'   --要替换的字符串  
  ,@d_str='' --替换成的字符串  
   
  --定义游标,循环处理数据  
  declare   @id   int  
  declare   #tb   cursor   for   select   id   from   hello  
  open   #tb  
  fetch   next   from   #tb   into   @id  
  while   @@fetch_status=0  
  begin  
  --字符串替换处理  
  declare   @p   varbinary(16),@postion   int,@rplen   int  
  select   @p=textptr(content),@rplen=len(@s_str),@postion=charindex(@s_str,content)-1   from   hello   where   id=@id  
  while   @postion>0  
  begin  
  updatetext   hello.content   @p   @postion   @rplen   @d_str  
  select   @postion=charindex(@s_str,content)-1   from   hello   where   id=@id  
  end  
   
  fetch   next   from   #tb   into   @id  
  end  
  close   #tb  
  deallocate   #tb  
   
  --显示结果  
  select   *   from   hello  
   
  --删除数据测试环境  
  drop   table   hello  

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号