SQLite TRIM function

SQLite’s TRIM function is used to remove leading or trailing characters (or both) from a given string. This function takes one mandatory argument, which is the string to be trimmed, and two optional arguments, specifying the characters to be removed from the beginning and end of the string.


The syntax for the TRIM function in SQLite is as follows:

TRIM(input_string, trim_character )

input_string: This is the string that you want to trim.

trim_character: This argument specifies the character or set of characters to be removed from the string. If you don’t specify a trim character, the default is to remove whitespace characters (spaces, tabs, and newlines).


Here are a few examples of how you might use the TRIM function in SQLite:

-- Trim whitespace from both ends of a string
SELECT TRIM('   hello, world   '); 
-- Returns 'hello, world'

-- Trim the character to be removed from the string
SELECT TRIM('SQLite tutorAAA','A');
-- Returns 'SQLite tutor'

In all of these examples, the TRIM function is used to remove unwanted characters from the input string. This can be particularly useful when working with user input, where you might want to strip leading or trailing whitespace or remove specific characters that the user is not allowed to enter.