RPAD () and RTRIM() in MariaDB

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
('w3wiki.net', 20, 'A');

Output :

'w3wiki.netAAA'

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('w3wiki    ');

Output :

'w3wiki

Example-2 :

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

Output :

'    gfg is the best portal'

Example-3 :

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

Output :

'arti@cle@!!!'

Contact Us