Back
Next
Now SQL Tutorial will explain the SQL TRIM function, in SQL Trim Function is used to remove specified prefix or
suffix from a string. The most common pattern being removed is white
spaces. This function is called in different ways with all the major databases
such as Oracle, MySQL and MS SQL Server.
Syntax for SQL Trim Function
►MySQL Syntax : TRIM(), RTRIM(), LTRIM()
►Oracle Syntax : RTRIM(), LTRIM()
►SQL Server Syntax: RTRIM(), LTRIM()
The syntax for these trim functions in query analyzer is as under.
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.
LTRIM(str):
Removes all white spaces from the beginning of the string.
RTRIM(str):
Examples of SQL Trim Function
Removes all white spaces at the end of the given string.
Example of SQL TRIM Function.
SELECT TRIM(' Sample ');
Result of SQL Trim Function Example
'Sample'
Example of SQL LTRIM Function.
SELECT LTRIM(' Sample ');
Result of SQL LTRIM Function Example
'Sample '
Example of SQL RTRIM Functiom
SELECT RTRIM(' Sample ');
Result of SQL RTRIM Function Example
' Sample'
Back
Next
|