Declaration
SUBSTRING(str, pos)
SUBSTRING(str, pos, len)
SUBSTRING(str FROM pos)
SUBSTRING(str FROM pos FOR len)
Description
Returns a substring of str starting at position pos and with a length of len. If any parameter is NULL, NULL is returned. This function is an alias for SUBSTR().
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 to the beginning ofstr.An empty string is returned if
lenis less than or equal to 0, or if the starting position specified byposis invalid.
Examples
obclient> SELECT
SUBSTRING('abcdefg', 3),
SUBSTRING('abcdefg', 3, 2),
SUBSTRING('abcdefg', -3),
SUBSTRING('abcdefg', 3, -2),
SUBSTRING('abcdefg' from -4 for 2)
\G
*************************** 1. row ***************************
SUBSTRING('abcdefg', 3): cdefg
SUBSTRING('abcdefg', 3, 2): cd
SUBSTRING('abcdefg', -3): efg
SUBSTRING('abcdefg', 3, -2):
SUBSTRING('abcdefg' from -4 for 2): de
1 row in set