The substring functions provide a way to extract a portion of a string. All that’s needed is the string to work with, the position to start from, and how many characters to extract. Use the LEFT, RIGHT, and SUBSTRING functions to do the extraction
LEFT:- Takes the string and the number of characters to extract from the start of the string.
For Example: LEFT(‘6128238193’,3)
RIGHT:- Takes the string and the number of characters to extract from the end of the string.
For Example: SUBSTR(‘6128238193’,4,3)
SUBSTR:- Takes the string and the number of characters to extract beginning with a certain position in the string.
For Example: RIGHT(‘6128238193’, 4)
Adding the formatting to a phone number using LEFT, RIGHT,and SUBSTR
For example: if a database has phone numbers stored in a 10-digit string without any formatting, the numbers could be displayed with the formatting by using the code
SELECT CONCAT('(',LEFT('6128238193',3),')',SUBSTR('6128238193',4,3),'-',RIGHT('6128238193', 4));
These Commands Return: (612)823-8193