• 周一. 10 月 7th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

mysql字符串查找位置取前部分

admin

11 月 28, 2021

有mysql路径字段,

E:code-py-download价图片202100501733-68590-8915ad8329a942f38fcb74306212a067-0.png

 如何取最后一个   前面部分?

SELECT LOCATE('\',path_names_png),path_names_png FROM `yfyj`

select substring_index(path_names_png,'\',-1) from yfyj
SELECT SUBSTRING_INDEX('and_this_may_go_like_this_too', '_', -1);
length对中文长度不好
SELECT path_names_png, LEFT(path_names_png, LENGTH(path_names_png) - LOCATE('\', REVERSE(path_names_png))) from yfyj

char_length中文长度OK
SELECT path_names_png, LEFT(path_names_png, char_length(path_names_png) - LOCATE('\', REVERSE(path_names_png))) from yfyj

发表回复