[MySQL]SUBSTRING_INDEX()
MySQL 문자열 함수와 연산자
SUBSTRING_INDEX()
-
SUBSTRING_INDEX(str, delim, count)
의 형태
Returns the substring from strikng str before count occurences of the delimiter delim. If count is positive, everything to the left of the final delimiter(counting from the left) is returned. If count is negative, everything to the right of the final delimter(counting from the right) is returned.
SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.
mysql> SELECT SUBSTRING_INDEX('www.mysql.com','.', 2);
+-----------------------------------------+
| SUBSTRING_INDEX('www.mysql.com','.', 2) |
+-----------------------------------------+
| www.mysql |
+-----------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT SUBSTRING_INDEX('www.mysql.com','.', -2);
+------------------------------------------+
| SUBSTRING_INDEX('www.mysql.com','.', -2) |
+------------------------------------------+
| mysql.com |
+------------------------------------------+
1 row in set (0.00 sec)