Name
substr() — Extract a substring
Common Usage
substr(string
,index
,count
) substr(string
,index
)
Description
The substr()
function extracts and returns a
substring from
. The position of the substring is determined by
string
and its length is determined by index
.count
If any parameter is NULL, a NULL will
be returned. Otherwise, if
is not a BLOB it will be assumed to be a text value.
The string
and index
parameters will be interpreted as integers. If
count
is not given, it will effectively be set to an
infinitely large positive value.count
If
is positive, it is used to index characters from the
beginning of index
. The first character has an index of 1. If string
is negative, it is used to index characters from the
end of index
. In that case, the last character has an index of ‒1.
An string
of 0 will result in undefined behavior.index
If
is positive, then count
number of characters, starting with the indexed
character, will be included in the returned substring. If
count
is negative, the returned substring will consist of
count
number of characters, ending with the indexed
character. The returned substring may be shorter than count
if the indexed position is too close to the beginning
or end of count
. A string
of zero will result in an empty string.count
This function can also be used on BLOB
values. If
is a BLOB, both the string
and index
values will refer to bytes, rather than characters, and the returned value will be a BLOB, ...count
Get Using SQLite now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.