替换col,mysql中的一些字符串

编程入门 行业动态 更新时间:2024-10-12 03:26:53
本文介绍了替换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中的一些字符串

本文发布于:2023-11-30 07:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   col   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!