SUBSTR(x,a,b) is a string function that outputs part of x (character string with length n).
|
Result of the SUBSTR(x,a,b) function |
SUBSTR(x,a,b) |
Part of the character string x that starts at the ath character and is b characters long. |
SUBSTR(x,a) |
SUBSTR(x,a,n-a+1) supplies all of the characters in the character string x from the ath character to the last (nth) character. |
b is an unsigned integer |
SUBSTR(x,a,b) b can also have a value that is greater than (n-a+1). |
b is not an unsigned integer |
SUBSTR(x,a,b) b must not be greater than (n-a+1). |
b>(n-a+1) |
SUBSTR(x,a) As many blanks (code attribute ASCII, UNICODE) or binary zeros (code attribute BYTE) are appended to the end of this result as are needed to give the result the length b. |
x, a or b is the NULL value |
Example table: customer
The SUBSTR function is used to reduce the firstname to one letter, add a period and a blank, and then concatenate it with the name.
SELECT SUBSTR (firstname,1,1)&'. '&name name, city
FROM customer WHERE firstname IS NOT NULL
NAME |
CITY |
J. Porter |
New York |
M. Porter |
Los Angeles |
S. Peters |
Los Angeles |
P. Brown |
Hollywood |
M. Porter |
New York |
G. Howe |
New York |
F. Randolph |
Los Angeles |
J. Peters |
Los Angeles |
S. Brown |
Los Angeles |
A. Jackson |
Los Angeles |
T. Adams |
Los Angeles |
M. Griffith |
New York |
I. Braun |
Los Angeles |