SQL SUBSTR Function Explained
The SUBSTR function in SQL is used to extract a substring from a string. Essentially, the SUBSTR function extracts a specified length of characters starting from a given position in a string.
The typical grammar format is as follows:
SUBSTR(string, start, length)
- Original string from which to extract the substring.
- Start: The starting position of the substring (index starts at 1).
- length: the length of the substring to be extracted.
For example, if we have a string ‘Hello, World!’ and we want to extract the substring ‘World’ from it, we can use the following SQL query:
SELECT SUBSTR('Hello, World!', 8, 5);
The above query will return the result as ‘World’.