Condividi tramite


CONCAT - Linguaggio di query in Cosmos DB (in Azure e Fabric)

La CONCAT funzione restituisce una stringa che è il risultato della concatenazione di più campi da un documento.

Sintassi

CONCAT(<string_expr_1>, <string_expr_2> [, <string_expr_N>])

Arguments

Description
string_expr_1 Prima espressione stringa nell'elenco.
string_expr_2 Seconda espressione stringa nell'elenco.
string_expr_N Espressioni stringa facoltative, che possono contenere un numero variabile di espressioni fino all'Nth elemento nell'elenco.

Tipi restituiti

Restituisce un'espressione stringa.

Esempi

Questa sezione contiene esempi di come usare questo costrutto di linguaggio di query.

Si consideri questo set di documenti di esempio all'interno della Products raccolta per questi esempi.

[
  {
    "name": "Stilld rope",
    "category": "gear",
    "sku": "66403",
    "detailCategory": "gear-climb-ropes"
  },
  {
    "name": "Orangas rope",
    "category": "gear",
    "sku": "66404",
    "detailCategory": "gear-climb-ropes"
  },
  {
    "name": "Vonel Rope",
    "category": "gear",
    "sku": "66400",
    "detailCategory": "gear-climb-ropes"
  },
  {
    "name": "Ferpal Ropes",
    "category": "gear",
    "sku": "66401",
    "detailCategory": "gear-climb-ropes"
  },
  {
    "name": "Cotings rope",
    "category": "gear",
    "sku": "66402",
    "detailCategory": "gear-climb-ropes"
  }
]

Concatenare le stringhe

In questo esempio, la CONCAT funzione viene usata per concatenare due stringhe arbitrarie.

SELECT VALUE
  CONCAT("Ferpal", "Ropes")
[
  "FerpalRopes"
]

Concatenare i campi del prodotto

In questo esempio, la CONCAT funzione viene usata per concatenare i campi di un prodotto nella categoria "heavy-coats".

SELECT VALUE
  CONCAT(p.sku, "-", p.detailCategory)
FROM
  products p
WHERE
  p.detailCategory = "gear-climb-ropes"
[
  "66403-gear-climb-ropes",
  "66404-gear-climb-ropes",
  "66400-gear-climb-ropes",
  "66401-gear-climb-ropes",
  "66402-gear-climb-ropes"
]

Osservazioni:

  • Questa funzione non usa l'indice.