共用方式為


STRINGTOARRAY - Cosmos DB 中的查詢語言 (在 Azure 和 Fabric 中)

STRINGTOARRAY 函數會將字串運算式轉換成陣列。

適用於 NoSQL 的 Azure Cosmos DB 系統函式,傳回轉換成陣列的字串運算式。

語法

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" ]
    ]
  }
]

備註

  • 此函式不會使用索引。