📜  sqlite trim - SQL (1)

📅  最后修改于: 2023-12-03 15:20:18.220000             🧑  作者: Mango

SQLite Trim - SQL
Introduction

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.

Syntax

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:
    • 'both': This is the default value. It trims both leading and trailing characters.
    • 'leading': It trims only leading characters.
    • 'trailing': It trims only trailing characters.
  • 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.
Examples

Here are some examples to illustrate the usage of TRIM function in SQLite:

Example 1:

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'

Example 2:

In this example, we will use the LEADING mode to trim only leading spaces from a string.

SELECT TRIM('LEADING', '0', '00012345');

Output:

'12345'

Example 3:

In this example, we will use the TRAILING mode to trim only trailing spaces from a string.

SELECT TRIM('TRAILING', '-', '12345----');

Output:

'12345'