---
title: "SUBSTR"
description: "The SUBSTR SQL function gets a substring from the input."
language: en
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/substr
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/sql-functions/substr
updated: 2026-08-09T00:00:00Z
license: https://documentation.invantive.eu/en/
---

## Syntax
```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> SUBSTR[SUBSTR]:::quoted
    SUBSTR --> End((END))
```

## Purpose
The `SUBSTR` SQL function gets a substring from the input.

See also [[INSTR]], [[LEFT]] and [[RIGHT]].

Parameters:
- Input (`varchar2`): text to gather the substring from.
- Start (`int32`): start position.
- Length (optional, `int32`): maximum length of the substring.

Returns: the substring from the original input.

## Examples
The following example retrieves the first two characters of `abc`:
```sql
select substr('abc', 1, 2)

-------------------
ab
```
The following example retrieves the substring starting at the second character to the end:
```sql
select substr('abc', 2)

-------------------
bc
```
The following example retrieves the last two characters of `abcdef` using a negative start position:
```sql
select substr('abcdef', -2)

-------------------
ef
```