SUBSTR

All functions > STRING > SUBSTR

Extracts a substring from a string starting at a specified position.

Syntax

SUBSTR(expr, start[, length])
sql

Arguments

ParameterTypeRequiredDescription
stringVARCHARYesString to extract from
startBIGINTYesStarting position (1-indexed, or negative to count from end)
lengthBIGINTNoNumber of characters to extract (optional, defaults to end of string)

Returns

Extracted substring

Notes

  • Start position is 1-indexed
  • Negative start position counts from end of string
  • If length omitted, extracts to end of string
  • If length exceeds remaining string, returns what's available

Examples

Last update at: 2025/10/13 10:23:46