INDEX_OF (Azure Cosmos DB)INDEX_OF (Azure Cosmos DB)
适用于:
SQL API
返回第一个指定的字符串表达式中第一次出现第二个字符串表达式的起始位置,如果未找到字符串,则返回 -1。Returns the starting position of the first occurrence of the second string expression within the first specified string expression, or -1 if the string is not found.
语法Syntax
INDEX_OF(<str_expr1>, <str_expr2> [, <numeric_expr>])
参数Arguments
str_expr1str_expr1
是要搜索的字符串表达式。Is the string expression to be searched.
str_expr2str_expr2
是要搜索的字符串表达式。Is the string expression to search for.
numeric_expr 可选数值表达式,用于设置搜索开始位置。numeric_expr Optional numeric expression that sets the position the search will start. str_expr1 中的第一个位置为 0。The first position in str_expr1 is 0.
返回类型Return types
返回数值表达式。Returns a numeric expression.
示例Examples
以下示例将返回 "abc" 内不同子字符串的索引。The following example returns the index of various substrings inside "abc".
SELECT INDEX_OF("abc", "ab") AS i1, INDEX_OF("abc", "b") AS i2, INDEX_OF("abc", "c") AS i3
下面是结果集:Here is the result set.
[{"i1": 0, "i2": 1, "i3": -1}]