惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - Hoooooo

华为交换机系统视图状态system-view超时设置 access trunk hybird untagged和tagged区别 WIN系统命令行添加防火墙配置 yum 安装包时解决依赖关系 Shell脚本--磁盘空间有超过80%时发信息 dos修改字符串排序,可用于修改文件名 linux系统调优用命令 centos7安装配置vnc和远程桌面,WIN10 mstsc远程linux gnome桌面 在linux系统中curlftpfs自动挂载ftp 文件抽取 win10 ie ActiveX 对应注册表编号 AUTUCAD2017 key 五种开源协议(BSD,Apache,GPL,LGPL,MIT) vim 编辑不显示以#或其它开始的行 mysql忘记root密码解决办法 Redhat 7及Centos 7系统网卡启动 mysql ROOT管理员密码修改 awk字符意义 redhat 7安装oracle 11gr2
mysql中字符查询与替换
Hoooooo · 2018-07-24 · via 博客园 - Hoooooo

select * from tablename where column like "%str%"----------------------查询表中的某列里包含某str的行

update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[url=',content)-locate('[/url]', content)),'')----------替换content内容里面以[url=开始并以[/url]结束之间的所有字符

update tablename set column =replace(column,'str','')-------------------替换表中某列里内容为str的字符串

update table set content=left(content,locate('str',content)+1)-----------删除表中某列里str后的内容

select trim(leading 'x' from 'xxxadminxxx')-----------------------------------删除字符串xxxadminxxx前xxx

select trim(trailing 'x' from 'xxxadminxxx')---------------------------------- -删除字符串xxxadminxxx后xxx 

select trim(both 'x' from 'xxxadminxxx')---------------------------------------删除字符串xxxadminxxx前后的xxx

delete from `表` where `字段` not like '%指定字符1%'--------------------删除不包含某字符串的记录

delete from `表` where `字段` like '%指定字符1%' or like '%指定字符2%' or like '%指定字符3%'------------删除包含某字符串的记录

以下为mysql删除两字符间所有字符的测试过程,参考过程来源博客见最后备注:

update ear_bbs_threads_content set content = dbo.RegexReplace('<*>','',content,1,1);
update ear_bbs_threads_content set content =replace(content,'[url*url]','') where tid >=100 and tid <=1000
update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[/url]', content)-locate('[url=',content)),'')
update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[/url]', content))),'')

update ear_bbs_threads_content set content = replace(content, substring(content, locate('[url=', content),locate('[url=',content)-locate('[/url]', content)),'')

其过程详细说明为:

使用 SubString字符串截取函数
SubString(string, int, int)
返回第一个参数中从第二个参数指定的位置开始、第三个参数指定的长度的子字符串。
然后用update set即可达到删除字符串的前两个字符的效果
sql
update table set name= substring(name,3,len(name)-2);
解释:更新table表中name字段
substring(name,3,len(name)-2);表示返回从name字段的第三个字符之后的所有字符
效果就是删除前2个字符了
len(name)表示返回name字段的长度

参考地址为百度知道的:https://zhidao.baidu.com/question/588857422353045925.html