Introduction:
If you need to extract a substring or create a longer string by combining multiple strings, there are a few methods you can use. To extract a specific portion of a string, you can utilize a substring-extraction API functions provided by SQL.
On the other hand, if you want to combine strings, you can use CONCAT(). It's possible to extract and display different parts of a string using functions like LEFT(), MID(), and RIGHT(). These functions can extract substrings from the left, middle, or right side of a string.
Command:
SELECT CustomerName, LEFT(CustomerName,2), MID(CustomerName,3,1), RIGHT(CustomerName,3) FROM Customers;
Results:
Number of Records: 91
CustomerName | Expr1001 | Expr1002 | Expr1003 |
Alfreds Futterkiste | Al | f | ste |
Ana Trujillo Emparedados y helados | An | a | dos |
Antonio Moreno Taquería | An | t | ría |
Around the Horn | Ar | o | orn |
Berglunds snabbköp | Be | r | köp |
Blauer See Delikatessen | Bl | a | sen |
Blondel père et fils | Bl | o | ils |
Bólido Comidas preparadas | Bó | l | das |
Bon app' | Bo | n |
Explanation:
The second parameter in LEFT() and RIGHT() specifies the number of characters to retrieve from the left or right end of the string.
In MID(), the second parameter represents the starting position of the desired substring (starting from 1), while the third parameter indicates the number of characters to retrieve.