SUBSTR(x,a,b) 

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 (n th) 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, EBCDIC) 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

NULL value

 

Model 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

?. DATASOFT

Los Angeles

P. Brown

Los Angeles

M. Jackson

Hollywood

G. Howe

New York

F. Miller

New York

R. Brown

Los Angeles

S. Murphy

Los Angeles

B. Smith

Los Angeles

A. Jones

Los Angeles

F. O’Brien

Los Angeles

P. Johnson

New York

E. Thomas

Los Angeles