Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

RPAD () and RTRIM() in MariaDB

  • Last Updated : 14 Dec, 2020

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 :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

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@!!!'
My Personal Notes arrow_drop_up
Recommended Articles
Page :