Syntax
SUBSTR(str, pos)
SUBSTR(str, pos, len)
SUBSTR(str FROM pos)
SUBSTR(str FROM pos FOR len)
Purpose
You can call this function to return a substring of str. The start position is pos, and the length of the substring is len characters. If any argument is NULL, the function returns NULL.
If
lenis not specified, the returned substring starts from the positionpostill the end ofstr.If the value of
posis negative, the start position is reversely determined from the end ofstr.If
lenis less than or equal to 0, or the start position specified byposis 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 (0.01 sec)