📅  最后修改于: 2023-12-03 15:20:18.220000             🧑  作者: Mango
SQLite is a popular embedded relational database management system that supports SQL. One of the most commonly used SQL functions is TRIM
, which removes leading and trailing white spaces from a string.
The syntax for the TRIM
function in SQLite is as follows:
TRIM([mode], [trim_string], [string_to_trim])
mode
: This is an optional parameter that specifies which characters to trim from the string. It can be one of the following values:trim_string
: This is an optional parameter that specifies the character(s) to be trimmed from the string. If not provided, the default value is a space character.string_to_trim
: This parameter specifies the string that needs to be trimmed. Here are some examples to illustrate the usage of TRIM
function in SQLite:
In this example, we will use the default mode to trim both leading and trailing spaces from a string.
SELECT TRIM(' Hello World ');
Output:
'Hello World'
In this example, we will use the LEADING
mode to trim only leading spaces from a string.
SELECT TRIM('LEADING', '0', '00012345');
Output:
'12345'
In this example, we will use the TRAILING
mode to trim only trailing spaces from a string.
SELECT TRIM('TRAILING', '-', '12345----');
Output:
'12345'