替换col,mysql中的一些字符串 [英] Replace some string in col , mysql

查看:71
本文介绍了替换col,mysql中的一些字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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 REPLACE

mthod但是我得到了这个结果

/ 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.


这篇关于替换col,mysql中的一些字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆