Very well done! Okay. The functions we've learned so far operated on all the string values, but we can also manipulate certain fragments or even single letters.
We'll start off with substring(x, y)
. Take a look:
SELECT substring(name, 2)
FROM item;
What does the function substring
do? It returns part of the string starting from the character specified as y, which must be an integer value.
In this case, if the name is 'TripCare' and y = 2, we'll get 'ripCare' as the result, because the database will start at the second character, which is 'r'.
If the integer y you provide is larger than the whole string length, then you will get an empty string ''
as a result.
In Oracle, this function is called substr()
.