STRINGTOARRAY - Cosmos DB 中的查询语言(在 Azure 和 Fabric 中)

STRINGTOARRAY 函数将字符串表达式转换为数组。

一个 Azure Cosmos DB for NoSQL 系统函数,该函数返回转换为数组的字符串表达式。

Syntax

STRINGTOARRAY(<string_expr>)

Arguments

Description
string_expr 字符串表达式。

返回类型

返回数组。

例子

本部分包含有关如何使用此查询语言构造的示例。

将字符串转换为数组

在此示例中,该 STRINGTOARRAY 函数用于将各种字符串值分析为数组。

SELECT VALUE {
  parseEmptyArray: STRINGTOARRAY("[]"),
  parseArray: STRINGTOARRAY('[ "coats", "gloves", "hats" ]'),
  complexArray: STRINGTOARRAY('[ { "types": [ "coats", "gloves" ] }, [ "hats" ], 76, false, null ]'),
  nestedArray: STRINGTOARRAY('[ [ "coats", "gloves" ], [ "hats" ] ]'),
  invalidArray: STRINGTOARRAY("[ 'coats', 'gloves', 'hats' ]"),
  parseUndefined: STRINGTOARRAY(undefined),
  parseNull: STRINGTOARRAY(null)
}
[
  {
    "parseEmptyArray": [],
    "parseArray": [ "coats", "gloves", "hats" ],
    "complexArray": [
      {
        "types": [ "coats", "gloves" ]
      },
      [ "hats" ],
      76,
      false,
      null
    ],
    "nestedArray": [
      [ "coats", "gloves" ],
      [ "hats" ]
    ]
  }
]

注解

  • 此函数不使用索引。