The TRIM function in SQL is used to remove the head or end of a string.
The most common use is to remove whitespace from the beginning or end of the word. This function has different names in different repositories:
- Mysql:trim (), RTRIM (), LTRIM ()
- Oracle:rtrim (), LTRIM ()
- SQL Server:rtrim (), LTRIM ()
The syntax for various trim functions such as the following:
TRIM ([[position] [string to remove] from] string: Possible values for [position] are leading (beginning), TRAILING (end), or BOTH (beginning and ending). This function removes the string [to be removed] from the beginning, end, or beginning and end of the string. Assuming we don't have a list of [strings to remove], the blanks will be removed.
LTRIM (String): Removes all whitespace from the beginning of the string.
RTRIM (String): Removes whitespace from the end of all strings.
Example 1
SELECT TRIM (' Sample ');
Results:
' Sample '
Example 2
SELECT LTRIM (' Sample ');
Results:
' Sample '
Example 3
SELECT RTRIM (' Sample ');
Results:
' Sample '
Linux measurements such as the following:
Reprint please specify: Xiao Liu
Linux SQL statement Concise tutorial---TRIM