Open In App

RPAD () and RTRIM() in MariaDB

Improve
Improve
Like Article
Like
Save
Share
Report

1. RPAD Function :
In MariaDB, The RPAD Function a string that is right-padded with a specified string to a certain length. In this function, the first parameter will be the string and the second parameter will be the length and the third parameter will be padding string. This function returns right-padded with a specified string to a given length. If the string is longer than length, the RPAD function will remove characters from string to shorten it to length characters.

Syntax :

RPAD( string, length, pad_string )

Parameter :

  • string –The string to right-pad.
  • Length –The length of the result after string has been right-padded.
  • Pad_string –The specified string to right-pad to string.

Return :
It returns a string that is right-padded with a specified string to a certain length.

Example-1 :

SELECT RPAD
('geeksforgeeks.org', 20, 'A');

Output :

'geeksforgeeks.orgAAA'

Example-2 :

SELECT RPAD
('Computer', 2, 'b');

Output :

'Co'

Example-3 :

SELECT RPAD
('Database', 10, 'xyz');

Output :

'Databasexy'

Example-4 :

SELECT RPAD('Post', 7, ' ');

Output :

'Post   '

2. RTRIM() Function :
In MariaDB, The RTRIM() Function removes all space characters from the right-hand side of a string. In this function, the first parameter will be the string. This works opposite to the LTRIM function. It will remove all the spaces from the right side.

Syntax :

RTRIM( string )

Parameter :

  • String –The string to trim the space characters from the right-hand side.

Return :
It will return a string with no space on the right side.

Example-1 :

SELECT RTRIM('geeksforgeeks    ');

Output :

'geeksforgeeks

Example-2 :

SELECT RTRIM('    gfg is the best portal    ');

Output :

'    gfg is the best portal'

Example-3 :

SELECT RTRIM('arti@cle@!!!');

Output :

'arti@cle@!!!'

Last Updated : 14 Dec, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads