SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len) : SUBSTRING « String Functions « MySQL Tutorial






The forms without a len argument return a substring from string str starting at position pos.

The forms with a len argument return a substring len characters long from string str, starting at position pos.

If pos is a negative value, the beginning of the substring is from the end of the string.

The position of the first character is reckoned as 1.

If len is less than 1, the result is the empty string.

SUBSTR() is a synonym for SUBSTRING().

MID(str,pos,len) is a synonym for SUBSTRING(str,pos,len).

mysql> SELECT SUBSTRING('ABCDEFGHIJK',5);
+----------------------------+
| SUBSTRING('ABCDEFGHIJK',5) |
+----------------------------+
| EFGHIJK                    |
+----------------------------+
1 row in set (0.00 sec)

mysql>








23.42.SUBSTRING
23.42.1.SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)
23.42.2.SUBSTRING('ABCDEFGHIJK' FROM 4);
23.42.3.SUBSTRING('ABCDEFGHIJK',5,6);
23.42.4.SUBSTRING('ABCDEFGHIJK', -3);
23.42.5.SUBSTRING('ABCDEFGHIJK', -5, 3);
23.42.6.SUBSTRING('ABCDEFGHIJK' FROM -4 FOR 2);
23.42.7.Use SUBSTRING with data in a table