×

MySQL RTRIM() function

In this context, we will learn how we can use the MySQL RTRIM() function with proper syntax and good examples.

Introduction of MySQL RTRIM() function

It is the function in MySQL that is used to remove trailing spaces from a string.

Syntax of the MySQL RTRIM() function

The syntax of the MySQL RTRIM() function is given as follows:

RTRIM(str)

Parameters or arguments used in MySQL RTRIM() function:

There is only one parameter accepted by the RTRIM() function in MySQL, which is given as follows:

Str: The string from which we want to remove trailing spaces.

Returns:

It will return a string after truncating all trailing spaces.

Application used for RTRIM() function:

The RTRIM() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL RTRIM() function:

Now we will look into some MySQL RTRIM() function examples and will explore how we can use the RTRIM function in MySQL.

Example-1:

In this example, we will Remove all the trailing spaces of a given string using the RTRIM Function in MySQL.

SELECT RTRIM ('JAVATPOINT')
AS RightTrimmedString;

Output:

JAVATPOINTRightTrimmedString
JAVATPOINTJAVATPOINT
1 row in set (0.00 sec)

Example-2:

In this example, we will Remove all the trailing spaces of a given string using the RTRIM Function in MySQL.

SELECT 'MySQL' AS String, RTRIM ('MySQL')
AS Tstring;

Output:

StringTstring
MySQLMySQL
1 row in set (0.00 sec)

Example-3:

When we are required to remove all the trailing spaces of column data, we can use the RTRIM function's help. To demonstrate, create a table named Pupil.

CREATE TABLE Pupil
(
Pupil_id INT AUTO_INCREMENT,
Pupil_name VARCHAR(100) NOT NULL,
Pupil_Class VARCHAR(20) NOT NULL,
PRIMARY KEY(Pupil_id )
);

Inserting some data to the Pupil table.

INSERT INTO Pupil
(Pupil_name, Pupil_Class )
VALUES
('Ananya Majumdar ', 'IX'),
('Anushka Samanta, ''X' ),
('Aniket Sharma ', 'XI' ),
('Anik Das ', 'X'
),
('Riya Jain ', 'IX' ),
('Tapan Samanta ', 'X' ),
('Deepak Sharma ', 'X'
),
('Ankana Jana ', 'XII'),
('Shreya Ghosh, ''X') ;

So, the Pupil Table is as follows.

mysql> select * from Pupil;

Output:

Pupil_idPupil_namePupil_Class
1Ananya MajumdarIX
2Anushka SamantaX
3Aniket SharmaXI
4Anik DasX
5Riya JainIX
6Tapan SamantaX
7Deepak SharmaX
8Ankana JanaXII
9Shreya GhoshX

Now, we are going to remove all trailing spaces from the Pupil_name column.

SELECT
Pupil_id, Pupil_name,
RTRIM( Pupil_name) AS TrimmedSname
FROM Pupil ;

Output:

Pupil_idPupil_nameTrimmedSname
1Ananya MajumdarAnanya Majumdar
2Anushka SamantaAnushka Samanta
3Aniket SharmaAniket Sharma
4Anik DasAnik Das
5Riya JainRiya Jain
6Tapan SamantaTapan Samanta
7Deepak SharmaDeepak Sharma
8Ankana JanaAnkana Jana
9Shreya GhoshShreya Ghosh

Application of MySQL RTRIM() function:

This function is used to remove trailing spaces from a string.

Summary:

In the above context, we have learned how we can use the RTRIM() function in MySQL used to remove trailing spaces from a string.


Related Topics

MySQL RIGHT() Function

In this context, we will learn how we can use the MySQL RIGHT() Function with proper syntax and good examples. Introduction of MySQL RIGHT() function The RIGHT() function in MySQL is used...

3 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL EXPORT_SET() function

In this context, we will learn how we can use the MySQL EXPORT_SET() function with proper syntax and good examples. Introduction of MySQL EXPORT_SET() function This function returns a string and shows...

3 minutes read.

MySQL Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL FORMAT() function

In this context, we will learn how we can use the MySQL FORMAT() function with proper syntax and good examples. Introduction of MySQL FORMAT() function This function in MySQL helps to format...

2 minutes read.

MySQL UPDATE JOIN

The UPDATE JOIN is a MySQL statement used to perform cross-table updates that means we can update one table using another table with the JOIN clause condition. The "update join"...

5 minutes read.

MySQL PI() function

In this context, we will learn how we can use the MySQL PI() function with proper syntax and good examples. Introduction of MySQL PI() function PI() function in MySQL is used to...

2 minutes read.

MySQL CURRENT_DATE() Function

In this context, we will learn how we can use the MySQL CURRENT_DATE() function to get the current date, and we will see in the two formats, such as strings...

2 minutes read.

MySQL RPAD() function

In this context, we will learn how we can use the MySQL RPAD() function with proper syntax and good examples. Introduction of MySQL RPAD() function RPAD() function in MySQL is used to...

2 minutes read.

MySQL ROUND() function

In this context, we will learn how we can use the MySQL ROUND() function with proper syntax and good examples. Introduction of MySQL ROUND() function The ROUND() function in MySQL is used...

3 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 minutes read.

MySQL QUARTER() function

In this context, we will learn how we can use the MySQL QUARTER() function with proper syntax and good examples. Introduction of MySQL QUARTER() function The QUARTER() function in MySQL returns the...

3 minutes read.

MySQL PERIOD_ADD() function

In this context, we will learn how we can use the MySQL PERIOD_ADD() function with proper syntax and good examples. Introduction of MySQL PERIOD_ADD() function In MySQL, PERIOD_ADD() function will help to...

2 minutes read.

MySQL INSERT() Function

In this context, we will learn how we can use the MySQL INSERT() function with proper syntax and good examples. Introduction of MySQL INSERT() function Basically, in MySQL, the INSERT function is...

2 minutes read.

MySQL Command line client Basic Queries

MySQL – command line client Basic Queries There are many queries to work with the MySQL command-line client. Today, we will explore MySQL basic queries and their function. The MySQL query...

8 minutes read.

MySQL RADIANS() function

In this context, we will learn how we can use the MySQL RADIANS() function with proper syntax and good examples. Introduction of MySQL RADIANS() function RADIANS() function in MySQL is used to...

2 minutes read.

MySQL DAY() function

In this context, we will learn how we can use the MySQL DAY() function with proper syntax and good examples. Introduction of MySQL DAY() function This function in MySQL is used to...

2 minutes read.

MySQL LENGTH() Function

In this context, we will learn how we can use the MySQL LENGTH() function with proper syntax and good examples. Introduction of MySQL LENGTH() function This function in MySQL is used to...

2 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL Control flow function

The control flow function uses values or operands for logical operations. These functions can works on single and multiple conditions. The control flow function is based on the Boolean expression....

3 minutes read.