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