- Overview
- Data types
- Commands
- Functions
- Overview
- Aggregate
- Conditional expression
- Conversion
- Date and time
- Numeric
- String
- Semi-structured data
- Window
- System
String slicing
Returns a range of characters from a string.
Syntax
<string>[<start>:<end>]
<string>[:<end>]
<string>[<start>:]
<string>[:]
Arguments
<string>
An expression that evaluates to a STRING.
<start>
The zero-based character position at which the result starts. A negative value counts backward from the end of the string. When omitted or NULL, the slice starts at the first character.
<end>
The zero-based character position at which the result stops. The character at this position is not included. A negative value counts backward from the end of the string. When omitted or NULL, the slice continues through the final character.
Returns
Returns a STRING. ScopeDB counts Unicode characters rather than UTF-8 bytes. Bounds outside the string are clamped to its valid range. If the normalized start position is greater than or equal to the end position, the result is an empty string. A NULL input string returns NULL.
ScopeQL does not provide a substr() function or support a step value in slice
syntax.
Examples
SELECT
'testing 1 2 3'[8:11] AS part,
'mystring'[-3:] AS tail,
'零1二3四5'[1:4] AS unicode_part;
+------+------+--------------+
| part | tail | unicode_part |
+------+------+--------------+
| 1 2 | ing | 1二3 |
+------+------+--------------+