Home >Database >Mysql Tutorial >mysql截取的字符串函数substring_index的用法_MySQL

mysql截取的字符串函数substring_index的用法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:06:011147browse

截取的字符串为15,151,152,16',可以看作是ip吧(虽然这里指的不是iP),

然后要截取每个逗号之前那部分

以下的意思是:在字符串中以逗号为索引,获取不同索引位的字符

结果如下:

SELECT SUBSTRING_INDEX('15,151,152,16',',',1); ==>得到结果为: 15
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('15,151,152,16',',',2),',',-1);==>得到结果为: 151
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('15,151,152,16',',',-2),',',1);==> 得到结果为:152
SELECT SUBSTRING_INDEX('15,151,152,16',',',-1);==>得到结果为: 16

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn