SUBSTR(x,a,b) is a string function that outputs part of the character string x (string specification of length n). Only expressions that have an alphanumeric value as a result are allowed as string specification x. LONG values are permitted. a and b are expressions.
|
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 a NULL value |
NULL value |
SELECT SUBSTR (firstname,1,1)&'. '&name
name, zip
FROM customer
WHERE firstname IS NOT NULL
The SUBSTR function is used to reduce the first name to one letter, add a period and a blank, and then concatenate it with the name.
NAME |
ZIP |
J. Porter |
10580 |
P. Brown |
48226 |
R. Brian |
75243 |
M. Griffith |
20005 |
M. Randolph |
60615 |
S. Smith |
75243 |
M. Jackson |
45211 |
R. Doe |
97213 |
G. Howe |
75243 |
F. Miller |
95054 |
S. Baker |
90018 |
J. Peters |
92714 |
A. Jenkins |
20903 |