SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)
SUBSTRING mysql function returns substring from a string. You can use this function with some above types.
If you pass only one argument with string which is position then this function returns the substring from the position which was passed as argument with function. If position is passed with negative (-) sign then position will count from right side of string.
If you pass position and length both argument then this will return a substring from position to given length.
I am giving some example which will explain this function-
mysql> SELECT SUBSTRING('Hello MySQL. This is mysql',3);
+-------------------------------------------+
| SUBSTRING('Hello MySQL. This is mysql',3) |
+-------------------------------------------+
| llo MySQL. This is mysql |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT SUBSTRING('Hello MySQL. This is mysql',3,9);
+---------------------------------------------+
| SUBSTRING('Hello MySQL. This is mysql',3,9) |
+---------------------------------------------+
| llo MySQL |
+---------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT SUBSTRING('Hello MySQL. This is mysql' FROM 3);
+------------------------------------------------+
| SUBSTRING('Hello MySQL. This is mysql' FROM 3) |
+------------------------------------------------+
| llo MySQL. This is mysql |
+------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT SUBSTRING('Hello MySQL. This is mysql' FROM 3 FOR 9);
+------------------------------------------------------+
| SUBSTRING('Hello MySQL. This is mysql' FROM 3 FOR 9) |
+------------------------------------------------------+
| llo MySQL |
+------------------------------------------------------+
1 row in set (0.00 sec)
0 Comment(s)