Syntax
SUBSTRING(str, pos)
SUBSTRING(str, pos, len)
SUBSTRING(str FROM pos)
SUBSTRING(str FROM pos FOR len)
Purpose
Returns the substring of str starting at pos and having a length of len. If any parameter is NULL, the function returns NULL. This function is an alias for SUBSTR().
If
lenis not specified, the substring starts atposand extends to the end ofstr.If
posis negative, the starting position is determined by counting backward from the end ofstr.If
lenis less than or equal to 0, or if the specifiedposis invalid, an empty string is returned.
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
