SQLite substr() Function
The SQLite substr()
function extracts and returns a substring from a specified string according to the specified starting position and length.
Syntax
This is the syntax of the SQLite substr()
function:
substr(string, start[, length])
Parameters
string
-
Required. The string to extract from.
start
-
Required. The starting position of the substring.
length
-
Optional. The length of the substring. The default is to the end of the string
string
.
Return value
The SQLite function substr()
extracts a substring of length length
starting at start
position from the string string
and returns it. If length
is not specified, substr()
extracts the substring from start
to the end of string string
.
If start + length
exceeds the length of string string
, return the substring from start
to the end of string string
.
If any parameter is NULL
, the function will return NULL
.
Examples
This example shows how to use the substr()
function to extract the substring starting at position 7 in a string.
SELECT substr('hello world', 7);
substr('hello world', 7)
------------------------
world
You can also specify the number of characters to extract (the length of the substring), for example:
SELECT substr('hello world', 7, 5);
substr('hello world', 7, 5)
---------------------------
world