当前位置:网站首页>Mysql怎样控制replace替换的次数?
Mysql怎样控制replace替换的次数?
2022-07-07 11:47:00 【全栈程序员站长】
我想把“ABC是ABC”替换成“123是ABC”,也就是找出第一个ABC替换成123,MYSQL命令应该怎么写?
UPDATE data SET body=REPLACE(body, ‘ABC’, ‘123’);我用这个命令时会把所有ABC都替换成123,不知道怎么控制替换次数,请高人指教。
hemu780924大哥的代码虽然能用,但是有个致命的缺陷,
比如"123是ABC",如果想找出XYZ并替换成OPQ,因为在"123是ABC"找不到XYZ,然后命令就会在"123是ABC"前面插入XYZ,这个不是我想要的啊!
update table1 set body =
concat(
SUBSTRING(body ,1,position('ABC' in body )-1),
'123',
substring(body ,position('ABC' in body )+length('ABC'))) where body like '%ABC%'
这里替换第一次的ABC ,没有ABC就不替换了
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113283.html原文链接:https://javaforall.cn
边栏推荐
- 2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers
- 2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
- 社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
- 室内ROS机器人导航调试记录(膨胀半径的选取经验)
- Summary of import, export, backup and recovery of mongodb
- [daily training] 648 Word replacement
- Dry goods | summarize the linkage use of those vulnerability tools
- Esp32 ① compilation environment
- PostgreSQL array type, each splice
- 云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
猜你喜欢
如何让join跑得更快?
高等數學---第八章多元函數微分學1
566. Reshaping the matrix
Esp32 construction engineering add components
社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
Write it down once Net a new energy system thread surge analysis
Thread pool reject policy best practices
566. 重塑矩阵
Enregistrement de la navigation et de la mise en service du robot ROS intérieur (expérience de sélection du rayon de dilatation)
Realize the IP address home display function and number home query
随机推荐
ESP32 ① 编译环境
[etc.] what are the security objectives and implementation methods that cloud computing security expansion requires to focus on?
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Cmake learning and use notes (1)
Xshell connection server changes key login to password login
Excerpt from "misogyny: female disgust in Japan"
Help tenants
Introduction and basic use of stored procedures
Error lnk2019: unresolved external symbol
Show the mathematical formula in El table
Mongodb command summary
LED light of single chip microcomputer learning notes
为租客提供帮助
现在网上开户安全么?那么网上开户选哪个证券公司?
【等保】云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
Flink | multi stream conversion
实现IP地址归属地显示功能、号码归属地查询
[QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
Fast development board pinctrl and GPIO subsystem experiment for itop-imx6ull - modify the device tree file
【日常训练】648. 单词替换