Declaration
SUBSTR(str, pos)
SUBSTR(str, pos, len)
SUBSTR(str FROM pos)
SUBSTR(str FROM pos FOR len)
Description
Returns a substring of str starting at position pos and having length len. If any parameter is NULL, the function returns NULL.
If
lenis not specified, the returned substring starts at positionposand ends at the end ofstr.If the
posvalue is negative, the starting position is determined by counting backward from the end ofstr.An empty string is returned if
lenis less than or equal to 0, or if the start position specified byposis invalid.
Examples
obclient> SELECT
SUBSTR('abcdefg', 3),
SUBSTR('abcdefg', 3, 2),
SUBSTR('abcdefg', -3),
SUBSTR('abcdefg', 3, -2),
SUBSTR('abcdefg' from -4 for 2)
\G
*************************** 1. row ***************************
SUBSTR('abcdefg', 3): cdefg
SUBSTR('abcdefg', 3, 2): cd
SUBSTR('abcdefg', -3): efg
SUBSTR('abcdefg', 3, -2):
SUBSTR('abcdefg' from -4 for 2): de
1 row in set