SQL statement concise tutorial for linux --- TRIM, SQL concise tutorial --- trim
The TRIM function in SQL is used to remove the character header or end of a string. The most common purpose is to remove the leading or trailing blank spaces. This function has different names in different databases:
- MySQL: TRIM (), RTRIM (), LTRIM ()
- Oracle: RTRIM (), LTRIM ()
- SQL Server: RTRIM (), LTRIM ()
Syntax of various trim functions:
TRIM ([[position] [string to be removed] FROM] string): The possible value of [position] is LEADING (start), TRAILING (end), or BOTH (start and end ). This function removes the [string to be removed] from the start, end, or end of the string. If we do not list what the [string to be removed] is, the blank space will be removed.
LTRIM (string): Removes white spaces from the start of all strings.
RTRIM (string): Removes the white space at the end of all strings.
Example 1
Select trim ('sample ');
Result:
'Sample'
Example 2
Select ltrim ('sample ');
Result:
'Sample'
Example 3
Select rtrim ('sample ');
Result:
'Sample'
Linux has been tested as follows:
Reprinted, please note: Xiao Liu
Bytes