Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-01 13:06:01
Original
1089 people have browsed it

截取的字符串为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
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!