MySQL Tutorial/String Functions/SUBSTRING INDEX — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:44, 26 мая 2010

SUBSTRING_INDEX(str,delim,count): Returns the substring from string str before count occurrences of the delimiter delim

If count is positive, everything to the left of the final delimiter is returned.

If count is negative, everything to the right of the final delimiter is returned.

SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.



   <source lang="sql">

mysql> mysql> SELECT SUBSTRING_INDEX("www.sqle.ru", ".", 2); +-------------------------------------------+ | SUBSTRING_INDEX("www.sqle.ru", ".", 2) | +-------------------------------------------+ | www.sqle | +-------------------------------------------+ 1 row in set (0.00 sec) mysql></source>


SUBSTRING_INDEX("www.java2s.com", ".", -2);

   <source lang="sql">

mysql> mysql> SELECT SUBSTRING_INDEX("www.sqle.ru", ".", -2); +--------------------------------------------+ | SUBSTRING_INDEX("www.sqle.ru", ".", -2) | +--------------------------------------------+ | sqle.ru | +--------------------------------------------+ 1 row in set (0.00 sec) mysql></source>