INDEX Function

Searches a character expression for a string of characters, and returns the position of the string's first character for the first occurrence of the string.

Category: Character
Returned data type: DOUBLE

Syntax

Arguments

target-expression

specifies any valid expression that evaluates to a character string.

Data type NCHAR
See <sql-expression>
FedSQL Expressions

search-expression

specifies any valid expression that evaluates to a character string to search for in target-expression.

Data type NCHAR
Tip Enclose a literal string of characters in single quotation marks.
See <sql-expression>
FedSQL Expressions

Details

The INDEX function searches target-expression, from left to right, for the first occurrence of the string specified in search-expression, and returns the position in target-expression of the string's first character. If the string is not found in target-expression, INDEX returns a value of 0. If there are multiple occurrences of the string, INDEX returns only the position of the first occurrence.

Comparisons

The VERIFY function returns the position of the first character in target-expression that does not contain search-expression where the INDEX function returns the position of the first occurrence of search-expression that is present in target-expression.

Example

The following statement illustrates the INDEX statement:
Statements
Results
select index('aabb','ab');
2

See Also

Last updated: February 23, 2017