我在mySql中有一个具有此值 / Test / test2 / Test / test2 的col我想将其替换为/ newText / test2 / test / test2 我尝试了什么: i尝试过
i have a col that have this value /Test/test2/Test/test2 in mySql i would like to replace it to be like this /NewText/test2/Test/test2 What I have tried: i have tried
UPDATE SET REPLACEmthod但是我得到了这个结果 / NewText / test2 / newText / test2 问题是我想改变第一个匹配的结果来替换
mthod but i get this result /NewText/test2/newText/test2 the problem is i want to change the first matching result to replace
推荐答案MySQL提供所有功能 [ ^ ]执行此类任务所需,即 POSITION (找到'Test'的第一次出现), SUBSTRING (仅检索字符串的一部分)包含第一次出现'Test') , REPLACE (仅在子字符串中替换'Test')和 CONCAT (用于将替换的子字符串连接到剩下的一个)。 但是在单个 UPDATE 语句中使用它们并不可行。 MySQL provides all the functions[^] needed to perform such a task, namely POSITION (to locate the first occurence of the 'Test'), SUBSTRING (to retrieve only the part of the string containing the first occurrence of 'Test'), REPLACE (to replace 'Test' only in the substring), and CONCAT (to concatenate the replaced substring with the remaining one). However it doesn't look practical to use all of them in a single UPDATE statement.