LTRIM and RTRIM Functions in SQL
For Complete YouTube Video: Click Here
In this class, we will understand LTRIM and RTRIM Functions in SQL.
We have already discussed the concepts of LPAD and PAD functions.
Table of Contents
LTRIM and RTRIM Functions in SQL
LTRIM and RTRIM will trim off the unwanted character from the left or right ends of the strings.
LTRIM and RTRIM Syntax
LTRIM(String, [‘set’]);
LTRIM is the name of the function.
The string is the name of the column, or it can be just the string.
Set will be provided with characters that are to be trimmed.
RTRIM(String, [‘set’]);
RTRIM is the name of the function.
The string is the name of the column, or it can be just the string.
Set will be provided with characters that are to be trimmed.
Examples of LTIM and RTRIM
To understand this, we will consider the table shown below.
The below are the queries and the outputs with the use of LTRIM and RTRIM.
SELECT LTRIM(name, ‘”‘) FROM students;
SELECT RTRIM(name, ‘.”‘) FROM students;
SELECT LTRIM(RTRIM(name, ‘.”‘), ‘”‘) FROM students;