SQLite String Functions

Savigo
You organize your data. Now organize your savings.
Set savings goals, track your progress, and stay on course.
Get Savigo for iPhone 

The following table shows the commonly used SQLite string functions that operate on an input string and return a new string or a numeric value.

NameDescription
SUBSTRExtract and return a substring with a predefined length starting at a specified position in a source string
TRIMReturn a copy of a string that has specified characters removed from the beginning and the end of a string.
LTRIMReturn a copy of a string that has specified characters removed from the beginning of a string.
RTRIMReturn a copy of a string that has specified characters removed from the end of a string.
LENGTHReturn the number of characters in a string or the number of bytes in a BLOB.
REPLACEReturn a copy of a string with each instance of a substring replaced by another substring.
UPPERReturn a copy of a string with all of the characters converted to uppercase.
LOWERReturn a copy of a string with all the characters converted to lowercase.
INSTRFind a substring in a string and return an integer indicating the position of the first occurrence of the substring.
Concatenation Operator ||Concatenate multiple strings into a single string.
CONCAT_WSConcatenate multiple string into a single string using a specified separator

 INSTR #

SELECT INSTR('SQLite String Functions','Functions') Position;
SQLite string functions - INSTR function

 LENGTH #

SELECT 
    LENGTH('SQLite');
SQLite string functions - LENGTH function

 LOWER #

SELECT
    LOWER('String Functions');
SQLite string functions - LOWER function

 LTRIM #

SELECT 
   LTRIM(' SQLite '),
   LENGTH(' SQLite ') LengthBefore,
   LENGTH(LTRIM(' SQLite ')) LengthAfter;
SQLite string functions - LTRIM function

 RTRIM #

SELECT
   RTRIM(' SQLite '),
   LENGTH(' SQLite ') LengthBefore,
   LENGTH(RTRIM(' SQLite ')) LengthAfter;
Image

 REPLACE #

SELECT 
    REPLACE('These are string functions', 'These', 'Those');
SQLite string functions - REPLACE function

 SUBSTR #

SELECT 
    SUBSTR('SQLite String Functions', 1, 6);
SQLite string functions - SUBSTR function

 TRIM #

SELECT 
    TRIM(' SQLite ');
SQLite string functions - TRIM function

 UPPER #

SELECT
    UPPER('String Functions');
SQLite string functions - UPPER function

Concatenation Operator || #

This example shows how to concatenate two strings into a single string:

SELECT 'Concatenation ' || 'Operator';
SQLite string functions - concatenation operator example

CONCAT #

The following statement uses the concat() function to concatenate multiple strings into a single string:

SELECT concat('Hello', ',', ' ', 'World','!') message;

Output:

message
-------------
Hello, World!

Was this tutorial helpful?