Scalar function
Aliases: substring
NULL arguments return NULL. Position 0 starts at the beginning. Nonpositive length returns an empty value. Strings count characters; binary values count bytes.
Syntax
Scalar
Arguments
Returns
- Type: STRING or BINARY
- NULL behavior: NULL arguments return NULL. Position 0 starts at the beginning. Nonpositive length returns an empty value. Strings count characters; binary values count bytes.
Properties
Units
- Input unit: Characters for STRING; bytes for BINARY.
- Output unit: Characters for STRING; bytes for BINARY.
- Omitting length reads through the end. Positions past the available input produce an empty value.
Usage notes
- Position and length are ordinary arguments. Neither is a pre-call configuration parameter or required to be a constant.
- MID requires all three arguments, including length. To read through the end without a length argument, use SUBSTRING.
Examples
Substring with a length limit
Negative and zero positions
Empty results
Binary positions count bytes
MID rejects a non-integer position
- MID requires integer position and length arguments. This call is rejected.
Expected error: Cannot apply ‘MID’
Limitations
- Use integer positions and lengths. Other numeric types and STRING values are outside these calling forms.
Last modified on October 15, 2026