The SUBSTRING (expression , start , length) function allows us to extract from an expression its part of a pecified length, starting from a specified initial position (start). Expression may be a character or a binary string, and also can have a text or image type. For example, if we need to get 3 characters in a ship name, starting from the 2nd character, then it's not quite easy to do it without the SUBSTRING function. And so we write:
SELECT name, SUBSTRING(name, 2, 3)
In case we need to extract all the characters, starting from the certain, we also can use this function. For example,
SELECT name, SUBSTRING(name, 2, LEN(name))
will give us all the characters in the names of the ships, starting from the second letter in the name. Pay attention that in order to specify the number of characters to extract I used the LEN
) function that returns a number of characters in the name. It's clearly that forasmuch as I need the characters, starting from the second, its number will be less than the whole number of the characters in the name. But it doesn't cause an error, because if a specified number of characters exceed a permissible number, all the characters until the end of a string will be extracted. That is why I take it with a reserve sparing myself the calculations.
Suggested exercises: 136