Jump to: navigation, search

Mysql RPAD

From w3cyberlearnings

Contents

MySQL RPAD Function

This function returns a string specifies by the right pad. When the LENGTH is shorter than the STR length, it will return based on the LENGTH, However if the LENGTH is longer than the STR's length, it will add the padstr to the return string after the STR. Check the example for detail.

Syntax RPAD

  • Str: A string input
  • Length: character length to be pad
  • Padstr: pad character
RPAD(Str,length,padstr);

Example 1: Length is 1, return only 1 and it is shorter than the Str

mysql> SELECT RPAD('good',1,'g');
+--------------------+
| RPAD('good',1,'g') |
+--------------------+
| g                  |
+--------------------+
1 row in set (0.00 sec)

Example 2: Length is 6, and longer than the str

mysql> SELECT RPAD('good',6,'g');
+--------------------+
| RPAD('good',6,'g') |
+--------------------+
| goodgg             |
+--------------------+
1 row in set (0.00 sec)

Example 3

mysql> SELECT RPAD('good',8,'?');
+--------------------+
| RPAD('good',8,'?') |
+--------------------+
| good????           |
+--------------------+
1 row in set (0.00 sec)

Related Links


Navigation
Web
SQL
MISC
References