函数说明:
SUBSTRING_INDEX(str,delim,count) 返回字符串 str 中在第 count 个出现的分隔符 delim 之前的子串。如果 count 是一个正数,返回从最后的(从左边开始计数)分隔符到左边所有字符。如果 count 是负数,返回从最后的(从右边开始计数)分隔符到右边所有字符。
举例:
[color=darkblue][/color]
mysql> select postId,substring_index(postId,'|',2) from user_resumetbl order by id desc limit 10;
+------------+-------------------------------+
| postId | substring_index(postId,'|',2) |
+------------+-------------------------------+
| |79 | |79 |
| |76|36|42 | |76 |
| |672|66|73 | |672 |
说明:
以上例子中substring_index(postId,'|',2)意思是,返回postId字段中第二个出现“|”字符的左边的字符串
SUBSTRING_INDEX(str,delim,count) 返回字符串 str 中在第 count 个出现的分隔符 delim 之前的子串。如果 count 是一个正数,返回从最后的(从左边开始计数)分隔符到左边所有字符。如果 count 是负数,返回从最后的(从右边开始计数)分隔符到右边所有字符。
举例:
[color=darkblue][/color]
mysql> select postId,substring_index(postId,'|',2) from user_resumetbl order by id desc limit 10;
+------------+-------------------------------+
| postId | substring_index(postId,'|',2) |
+------------+-------------------------------+
| |79 | |79 |
| |76|36|42 | |76 |
| |672|66|73 | |672 |
说明:
以上例子中substring_index(postId,'|',2)意思是,返回postId字段中第二个出现“|”字符的左边的字符串
本文详细介绍了SQL中的SUBSTRING_INDEX函数使用方法,该函数能够返回指定分隔符前后的子字符串。通过具体示例展示了如何根据分隔符及计数获取特定子串,适用于数据库查询与处理。
5488

被折叠的 条评论
为什么被折叠?



