## 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
```