SUBSTRING Function

Extracts a substring from a character string.

Category: Character
Returned data type: VARCHAR NVARCHAR

Syntax

SUBSTRING(character-string FROM position [FOR length])

Arguments

character-string

specifies any valid expression that evaluates to a character string. character-string is the source string that is searched for a substring.

Data type CHAR, VARCHAR, NVARCHAR

position

specifies the beginning character position.

Interaction If position is larger than the length of the source string, FedSQL returns a null value. For example, if you ask for a substring starting at character five but the source string is only four characters long, you get a null result.
Data type INTEGER

length

specifies the length of the substring to extract.

Interaction If length is zero, a negative value, or larger than the length of the expression that remains in string after position, FedSQL extracts the remainder of the expression.
Data type INTEGER
Tip If you omit length, FedSQL extracts the remainder of the expression.

Details

The SUBSTRING function returns a portion of an expression that you specify in character-string. The portion begins with the character that you specify by position, and is the number of characters that you specify in length.

Example

Table: AFEWORDS
The following statement illustrates the SUBSTRING function.
Statements
Results
select substring(word2 from 2 for 3);
HER
HIN
ODY

See Also

Functions:
Last updated: February 23, 2017