AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL Trim Function |
|
SQL > SQL String Functions >
Trim
The TRIM function in SQL is used to remove a specified prefix or suffix from a string. The most common pattern being removed is the white space. This function is called differently in different databases:
Key Takeaway: SQL provides TRIM, LTRIM, and RTRIM functions to remove unwanted leading and trailing whitespace or characters from strings. MySQL supports all three, while Oracle and SQL Server only support LTRIM and RTRIM.
SyntaxThe syntax for the TRIM function is as follows: [LOCATION] can be either LEADING, TRAILING, or BOTH. This function gets rid of the [remstr] pattern from either the beginning of the string or the end of the string, or both. If no [remstr] is specified, white spaces are removed. The syntax for the LTRIM function is as follows: LTRIM removes all white spaces from the beginning of the string. The syntax for the RTRIM function is as follows: RTRIM removes all white spaces at the end of the string. ExamplesExample 1: TRIM functionResult: 'Sample'
Example 2: LTRIM functionResult: 'Sample '
Example 3: RTRIM functionResult: ' Sample'
Frequently Asked Questions
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.