MySQL substring function

MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.

Syntax:

SUBSTRING(str, pos, len)

or

SUBSTRING(str FROM pos FOR len)

Arguments

Name       Description

str              A string.
pos             Starting position.
len              Length in characters.

Example : MySQL SUBSTRING() function

SELECT SUBSTRING(‘satyaprakash’,4,3);


 

mysql> SELECT SUBSTRING(‘satyaprakash’,4,3);
+—————————–+
| apr |
+—————————–+
1 row in set (0.00 sec)


mysql> SELECT SUBSTRING(‘satyaprakash’,5);
+———————————————————+
| aprakash |
+———————————————————+
1 row in set (0.00 sec)


mysql> SELECT SUBSTRING(‘satyaprakash’ FROM 4);
+———————————————————+
| yaprakash |
+———————————————————+
1 row in set (0.00 sec)


 

mysql> SELECT SUBSTRING(satyaprakash FROM -5 FOR 3) ;
+————————–+

| aka |

+————————–+
3 rows in set (0.00 sec)

 

 

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply