SQL Trim | Trim Command in SQL - sql - sql tutorial - learn sql

- 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.
- TRIM is a function that takes a character expression and returns that expression with leading and/or trailing pad characters removed.
- Optional parameters indicate whether leading, or trailing, or both leading and trailing pad characters should be removed, and specify the pad character that is to be removed.
This function is called differently in different databases:
- MySQL: TRIM( ), RTRIM( ), LTRIM( )
- Oracle: RTRIM( ), LTRIM( )
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialSyntax
Syntax
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialThe syntax for the TRIM function is as follows:
The syntax for the TRIM function is as follows:
TRIM( [ [LOCATION] [remstr] FROM ] str)
- [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 (str)
- LTRIM removes all white spaces from the beginning of the string.
The syntax for the RTRIM function is as follows:
RTRIM (str)
- RTRIM removes all white spaces at the end of the string.
Examples
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialExample 1: TRIM function
Example 1: TRIM function
SELECT TRIM(' Wikitechy ');
Result:
'Wikitechy'
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialExample 2: LTRIM function
Example 2: LTRIM function
SELECT LTRIM(' Wikitechy ');
Result:
'Wikitechy '
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialExample 3: RTRIM function
Example 3: RTRIM function
SELECT RTRIM(' Wikitechy ');
Result:
' Wikitechy'