SUBSTRING (Azure Cosmos DB)SUBSTRING (Azure Cosmos DB)

适用于: SQL API

返回字符串表达式的部分内容,该内容起于指定字符从零开始的位置,继续到指定长度或字符串结尾。Returns part of a string expression starting at the specified character zero-based position and continues to the specified length, or to the end of the string.


SUBSTRING(<str_expr>, <num_expr1>, <num_expr2>)  


是一个字符串表达式。Is a string expression.

是表示开始字符的数字表达式。Is a numeric expression to denote the start character. 值 0 是 str_expr 的第一个字符。A value of 0 is the first character of str_expr.

是一个数值表达式,表示要返回的 str_expr 的最大字符数。Is a numeric expression to denote the maximum number of characters of str_expr to be returned. 值为 0 或更小将导致空字符串。A value of 0 or less results in empty string.

返回类型Return types

返回一个字符串表达式。Returns a string expression.


以下示例返回“abc”中从位置 1 开始且长度为 1 个字符的子字符串。The following example returns the substring of "abc" starting at 1 and for a length of 1 character.

SELECT SUBSTRING("abc", 1, 1) AS substring  

下面是结果集。Here is the result set.

[{"substring": "b"}]  


此系统函数将从范围索引中获益(如果起始位置是 0)。This system function will benefit from a range index if the starting position is 0.

后续步骤Next steps