Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mySQL中搜索和替换特定模式_Mysql - Fatal编程技术网

在mySQL中搜索和替换特定模式

在mySQL中搜索和替换特定模式,mysql,Mysql,我有这样的字符串: @N05/3835412983/academy of sciences.html 其中3835412983和academy of sciences.html将在名为wp_4_posts的数据库表中的post_content列中有所不同 我是否可以使用通配符搜索来保留两个/和strip*.htm*之间的唯一id?@05左侧的所有内容都无法更改。/之间的数字需要保留。第二个/之后的项目可以完全剥离 手动操作,有数百个需要这样做 对于上述情况,最终结果将是: @N05/383541

我有这样的字符串:

@N05/3835412983/academy of sciences.html

其中
3835412983
academy of sciences.html
将在名为
wp_4_posts
的数据库表中的
post_content
列中有所不同

我是否可以使用通配符搜索来保留两个
/
和strip
*.htm*
之间的唯一id?
@05
左侧的所有内容都无法更改。
/
之间的数字需要保留。第二个
/
之后的项目可以完全剥离

手动操作,有数百个需要这样做

对于上述情况,最终结果将是:

@N05/3835412983/


结果将被写回数据库。

如果要提取中间元素,则可以使用
子字符串\u index()

这将提取第二个元素

根据编辑,您似乎希望:

select concat(substring_index(str, '/', 2), '/')
如果要更新该值,请执行以下操作:

update t
    set str = concat(substring_index(str, '/', 2), '/');

更新特定字符串,然后应使用
replace()
函数

语法:-

UPDATE table_name
SET column_name =
REPLACE(column_name,'OLD_STRING','NEW_STRING')
WHERE column_name = 'your condtition';
就你而言:-

UPDATE wp_4_posts
SET post_content =
REPLACE(post_content,'@N05/3835412983/academy-of-sciences.html','@N05/3835412983/');
如果您想要基于条件的结果

UPDATE wp_4_posts
SET post_content =
REPLACE(post_content,'@N05/3835412983/academy-of-sciences.html','@N05/3835412983/')
WHERE column_name = "values";

您想要搜索还是提取值?请显示您正在查找的结果。为清晰起见,添加了一些更多信息--对此表示抱歉。我是一个mySQL傻瓜--我是否可以登录到mySQL shell并键入这些内容?如何访问数据库->表->列?我不想破坏任何东西。
UPDATE wp_4_posts
SET post_content =
REPLACE(post_content,'@N05/3835412983/academy-of-sciences.html','@N05/3835412983/')
WHERE column_name = "values";