반응형
Example of MySQL SUBSTRING_INDEX()
특정 구분자로 문자열을 분리해 내야할때 필요하다.
mysql> SELECT ip, SUBSTRING_INDEX(ip,'.',1) AS part1, SUBSTRING_INDEX(SUBSTRING_INDEX(ip,'.',2),'.',-1) AS part2, SUBSTRING_INDEX(SUBSTRING_INDEX(ip,'.',-2),'.',1) AS part3, SUBSTRING_INDEX(ip,'.',-1) AS part4 FROM log_file; +-----------------+-------+-------+-------+-------+ | ip | part1 | part2 | part3 | part4 | +-----------------+-------+-------+-------+-------+ | 127.0.0.1 | 127 | 0 | 0 | 1 | | 192.128.0.15 | 192 | 128 | 0 | 15 | | 255.255.255.255 | 255 | 255 | 255 | 255 | +-----------------+-------+-------+-------+-------+ 3 rows in set (0.00 sec)
- See more at: http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php#sthash.UFdjNs2M.dpuf
출처 : http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php
반응형
'Story > mysql' 카테고리의 다른 글
MySQL 5.6에서 Invalid value error (0) | 2014.04.17 |
---|---|
mysql 에서 LOAD DATA INFILE 로 데이타 입력시 ERROR 1148 (42000) : The used command is not allowed 에러날경우 (0) | 2014.04.15 |
mdb 내용을 mysql 로 바꾸는 프로그램 (0) | 2014.02.24 |
한글먼저 영문 나중 으로 정렬하고자 할때 (0) | 2013.03.14 |
(펌) MySQL 5.5의 새로워진 것들 (0) | 2012.12.05 |