ARRAY_SLICE (Azure Cosmos DB)ARRAY_SLICE (Azure Cosmos DB)

返回部分数组表达式。Returns part of an array expression.


ARRAY_SLICE (<arr_expr>, <num_expr> [, <num_expr>])  


是任何数组表达式。Is any array expression.

用于开始数组的从零开始的数字索引。Zero-based numeric index at which to begin the array. 负值可用于指定相对于数组最后一个元素的起始索引,即 -1 引用数组中最后一个元素。Negative values may be used to specify the starting index relative to the last element of the array i.e. -1 references the last element in the array.

num_expr 可选数值表达式,用于设置生成的数组中的最大元素数。num_expr Optional numeric expression that sets the maximum number of elements in the resulting array.

返回类型Return types

返回一个数组表达式。Returns an array expression.


以下示例演示了如何使用 ARRAY_SLICE 获取数组的不同切片。The following example shows how to get different slices of an array using ARRAY_SLICE.

   ARRAY_SLICE(["apples", "strawberries", "bananas"], 1) AS s1,  
   ARRAY_SLICE(["apples", "strawberries", "bananas"], 1, 1) AS s2,
   ARRAY_SLICE(["apples", "strawberries", "bananas"], -2, 1) AS s3,
   ARRAY_SLICE(["apples", "strawberries", "bananas"], -2, 2) AS s4,
   ARRAY_SLICE(["apples", "strawberries", "bananas"], 1, 0) AS s5,
   ARRAY_SLICE(["apples", "strawberries", "bananas"], 1, 1000) AS s6,
   ARRAY_SLICE(["apples", "strawberries", "bananas"], 1, -100) AS s7      

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

           "s1": ["strawberries", "bananas"],   
           "s2": ["strawberries"],
           "s3": ["strawberries"],  
           "s4": ["strawberries", "bananas"], 
           "s5": [],
           "s6": ["strawberries", "bananas"],
           "s7": [] 


此系统函数不会使用索引。This system function will not utilize the index.

后续步骤Next steps