首页  编辑  

提取字符串中第N个分隔符分隔的数据

Tags: /MySQL/   Date Created:

用SUBSTRING_INDEX(SUBSTRING_INDEX('逗号分隔字符串', ',', N), ',', -1);即可

例如:

SET @arect = "105.971712,29.725534,106.249971,29.883985";

SET @_LEFT = SUBSTRING_INDEX(SUBSTRING_INDEX(@arect, ',', 1), ',', -1);

SET @_TOP = SUBSTRING_INDEX(SUBSTRING_INDEX(@arect, ',', 4), ',', -1);

SET @_RIGHT = SUBSTRING_INDEX(SUBSTRING_INDEX(@arect, ',', 3), ',', -1);

SET @_BOTTOM = SUBSTRING_INDEX(SUBSTRING_INDEX(@arect, ',', 2), ',', -1);

SELECT @_LEFT, @_RIGHT, @_TOP, @_BOTTOM;

SELECT (@arect IS NULL OR (106 BETWEEN @_LEFT AND @_RIGHT AND 29.87 BETWEEN @_BOTTOM AND @_TOP))