最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

SEO心得admin48浏览0评论
本文介绍了替换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.

发布评论

评论列表(0)

  1. 暂无评论