SQLite SUBSTR() Function
Example
Return 3 characters, from position 5:
SELECT SUBSTR('SQL Tutorial', 5, 3);
Try it Yourself »
Definition and Usage
The SUBSTR() function returns a part of a text. SUBSTRING() is another name for the same function.
The first character has position 1. A negative start position counts from the end of the text.
Syntax
SUBSTR(text, start, length)
Parameter Values
| Parameter | Description |
|---|---|
| text | Required. The text |
| start | Required. The position to start at. 1 is the first character, and -1 is the last character |
| length | Optional. The number of characters to return. If it is left out, the rest of the text is returned |
Technical Details
| Return type: | Text |
|---|
More Examples
Example
Return the first 5 characters of each customer name:
SELECT CustomerName, SUBSTR(CustomerName, 1, 5)
FROM Customers;
Try it Yourself »