SubString

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > String Functions >

SubString

Extracts a substring from a table column or character literal, specified in the column reference.

Syntax:

SubString( column_reference FROM start_index [FOR length] )

FROM is the character position at which the extracted substring starts within the original string. The index for FROM is based on the first character in the source value being 1.

FOR is optional, and specifies the length of the extracted substring. If FOR is omitted, the substring goes from the position specified by FROM to the end of the string.

The example below, applied to the literal string "ABCDE", returns the value "BCD".

SELECT SUBSTRING('ABCDE' FROM 2 FOR 3) AS Sub FROM country

 

In the SELECT statement below only the second and subsequent characters of the NAME column are retrieved.

Example #1:

SELECT SUBSTRING(name FROM 2) FROM country

Example #2:

The following shows how the commonly used Copy() function can be translated to use SubString()

SELECT Copy(LAST,1,1) as LETTER from TEST

Should be:

SELECT SubString(LAST from 1 for 1) as LETTER from TEST