Returns a substring starting at the character indicated by the
<offset> index and including the number of characters defined by the
<length>. Character indexing starts from index 1. The
<length> arguments must be constants.
SUBSTR(<string>, <offset> [, <length>])
| ||The string to be offset.|
| ||The starting position for the substring. 1 is the first character.|
| ||Optional. The number of characters to be returned by the |
In the example below, the string is offset by 1 and so the
SUBSTR command begins at the first letter, “h”. The
<length> of 5 indicates the resulting string should be only five characters long.
SELECT SUBSTR('hello world', 1, 5);
In this next example, there is no
<length> provided. This means all characters are included after the
<offset> index, which is 7.
SELECT SUBSTR('hello world', 7);