Skip to content

Commit 6655607

Browse files
committed
Add SUBSTRING
1 parent ea92b4f commit 6655607

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed
Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,56 @@
11
---
2-
title: SUBSTRING in Azure Cosmos DB query language
3-
description: Learn about SQL system function SUBSTRING in Azure Cosmos DB.
4-
author: ginamr
2+
title: SUBSTRING
3+
titleSuffix: Azure Cosmos DB for NoSQL
4+
description: An Azure Cosmos DB for NoSQL system function that returns a portion of a string using a starting position and length.
5+
author: jcodella
6+
ms.author: jacodel
7+
ms.reviewer: sidandrews
58
ms.service: cosmos-db
69
ms.subservice: nosql
7-
ms.topic: conceptual
8-
ms.date: 09/13/2019
9-
ms.author: girobins
10-
ms.custom: query-reference, ignite-2022
10+
ms.topic: reference
11+
ms.date: 07/24/2023
12+
ms.custom: query-reference
1113
---
12-
# SUBSTRING (Azure Cosmos DB)
14+
15+
# SUBSTRING (NoSQL query)
16+
1317
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1418

15-
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.
16-
19+
Returns part of a string expression starting at the specified position and of the specified length, or to the end of the string.
20+
1721
## Syntax
18-
22+
1923
```sql
20-
SUBSTRING(<str_expr>, <num_expr1>, <num_expr2>)
21-
```
22-
24+
SUBSTRING(<string_expr>, <numeric_expr_1>, <numeric_expr_2>)
25+
```
26+
2327
## Arguments
24-
25-
*str_expr*
26-
Is a string expression.
27-
28-
*num_expr1*
29-
Is a numeric expression to denote the start character. A value of 0 is the first character of *str_expr*.
30-
31-
*num_expr2*
32-
Is a numeric expression to denote the maximum number of characters of *str_expr* to be returned. A value of 0 or less results in empty string.
28+
29+
| | Description |
30+
| --- | --- |
31+
| **`string_expr`** | A string expression. |
32+
| **`numeric_expr_1`** | A numeric expression to denote the start character. |
33+
| **`numeric_expr_2`** | A numeric expression to denote the maximum number of characters of `string_expr` to be returned. |
3334

3435
## Return types
35-
36-
Returns a string expression.
37-
36+
37+
Returns a string expression.
38+
3839
## Examples
39-
40-
The following example returns the substring of "abc" starting at 1 and for a length of 1 character.
41-
42-
```sql
43-
SELECT SUBSTRING("abc", 1, 1) AS substring
44-
```
45-
46-
Here is the result set.
47-
48-
```json
49-
[{"substring": "b"}]
50-
```
40+
41+
The following example returns substrings with various lengths and starting positions.
42+
43+
:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/substring/query.sql" highlight="2-5":::
44+
45+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/substring/result.json":::
5146

5247
## Remarks
5348

54-
This system function will benefit from a [range index](../../index-policy.md#includeexclude-strategy) if the starting position is `0`.
49+
- This function benefits from a [range index](../../index-policy.md#includeexclude-strategy) if the starting position is `0`.
50+
- `numeric_expr_1` positions are zero-based, therefore a value of `0` starts from the first character of `string_expr`.
51+
- A value of `0` or less for `numeric_expr_2` results in empty string.
5552

5653
## Next steps
5754

5855
- [System functions Azure Cosmos DB](system-functions.yml)
59-
- [Introduction to Azure Cosmos DB](../../introduction.md)
56+
- [`StringEquals`](stringequals.md)

0 commit comments

Comments
 (0)