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 the various trim functions is as follows:
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. If we don't list what the [string to remove] is, the blanks will be removed.
LTRIM (String): Removes all whitespace from the beginning of the string.
RTRIM (String): Removes all whitespace from the end of the string.
Example 1
SELECT TRIM (' Sample ');
Results:
' Sample '
Example 2
SELECT LTRIM (' Sample ');
Results:
' Sample '
Example 3
SELECT RTRIM (' Sample ');
Results:
' Sample '
Linux is measured as follows:
Reprint please specify: Xiao Liu
Linux SQL statement Concise tutorial---TRIM