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 ([[location] [string to be removed] From] string): the possible value of [location] 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'
Usage of trim in VB:
Trim (STR) removes spaces at both ends of str. Sometimes trim is used as well as trim is not used. It is a good habit to use trim. but not absolute, for example, password = inputbox ("enter the password :")