SUBSTR: Extracting a Substring From a String Value (SQL)

How to:

The SUBSTR function returns a substring of a character value. You specify the start position of the substring within the value. You can also specify the length of the substring (if omitted, the substring extends from the start position to the end of the string value). If the specified length value is longer than the input string, the result is the full input string.

SUBSTRING is identical to SUBSTR.


Top of page

x
Syntax: How to Extract a Substring From a String Value
SUBSTR(arg FROM start-pos [FOR length]) 

or

SUBSTR(arg, start-pos [, length])

where:

arg

character string

Is the field containing the parent character string.

start-pos

Integer

Is the position within arg at which the substring begins.

length

Integer

If present, is the length of the substring. This function returns a varying character string. The data type of the result has a length equal to that of the input argument (although the value may be shorter).



Example: Extracting a Substring From a String Value

SUBSTR function returns a substring. This example,

SUBSTR('ABC' FROM 2)

Returns BC.

This example,

SUBSTRING('ABC' FROM 1 FOR 2)

returns AB.

This example,

SUBSTR('ABC', 10)

returns ABC.


iWay Software