SUBSTR
The SUBSTR() function extracts a specific number of characters from a string:
π Input and return will be of type string.
The start_position is used as the starting position, specifying the part from where the substring is to be returned. It is written as an integer value.
Input | Return |
start_position = 1 | The count starts from the first character. |
start_position < 0 start_position < string | The start_position is set to 1, and the count starts from the first character. |
start_position > string | Returns an empty substring. |
start_position = negative value | The count starts from the end of the string. |
The length is used to determine the number of characters to be extracted. It can be one or more characters.
Input | Return |
length = 0 | Returns an empty substring. |
length is not set | The function will start from the specified start_position and end at the last character of the string. |
length = negative value | Returns an error. |
In this example, we will set the start_position with the first six characters and have five characters extracted:
The updated table is shown below:
The following query will extract a string with length = 0:
It will display an empty output as there is no length specified:
Here we will check if the length is specified with a negative value:
Instead of extracting the string from the last characters, it will return an error as seen below:
We know that Watermelon only has ten characters, but this time, we will figure out if the specified start_position is larger than the stringβs characters:
It will display an empty output as shown below:
ο»Ώ