[英]MySQL remove final part of a string after specific character
I need to remove the last part of a string in a column where I have a field named "path" that looks like: 我需要在列中删除字符串的最后一部分,其中我有一个名为“path”的字段,如下所示:
images/prop/images/2034/22399_2034.JPG
I need everything after the last "/" to be deleted, in order to have 我需要删除最后一个“/”后的所有内容,以便删除
images/prop/images/2034/
instead of 代替
images/prop/images/2034/22399_2034.JPG
I have no idea if this is possible. 我不知道这是否可行。 Thanks. 谢谢。
You can combine MySQL's TRIM()
and SUBSTRING_INDEX()
functions: 您可以组合MySQL的TRIM()
和SUBSTRING_INDEX()
函数:
SELECT TRIM(TRAILING SUBSTRING_INDEX(path, '/', -1) FROM path)
FROM my_table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.