当前位置:网站首页>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
边栏推荐
- Deep understanding of array related problems in C language
- How did Guotai Junan Securities open an account? Is it safe to open an account?
- 华为镜像地址
- MySQL error 28 and solution
- 【面试高频题】难度 2.5/5,简单结合 DFS 的 Trie 模板级运用题
- Enregistrement de la navigation et de la mise en service du robot ROS intérieur (expérience de sélection du rayon de dilatation)
- LED light of single chip microcomputer learning notes
- PostgreSQL array type, each splice
- LeetCode简单题分享(20)
- Move base parameter analysis and experience summary
猜你喜欢
118. Yanghui triangle
Write it down once Net a new energy system thread surge analysis
数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】
Use of polarscatter function in MATLAB
QQ的药,腾讯的票
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
Help tenants
得物客服热线的演进之路
How to make join run faster?
随机推荐
C语言数组相关问题深度理解
1、深拷贝 2、call apply bind 3、for of for in 区别
2022-7-7 Leetcode 844.比较含退格的字符串
Mongodb slice summary
10 pictures open the door of CPU cache consistency
2022-7-6 Leetcode 977. Square of ordered array
LeetCode_二分搜索_中等_153.寻找旋转排序数组中的最小值
Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
Introduction to database system - Chapter 1 introduction [conceptual model, hierarchical model and three-level mode (external mode, mode, internal mode)]
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
. Net core about redis pipeline and transactions
Introduction and basic use of stored procedures
Realbasicvsr test pictures and videos
Esp32 series column
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
How to make join run faster?
Leecode3. Longest substring without repeated characters
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
高等數學---第八章多元函數微分學1
JS slow motion animation principle teaching (super detail)