Jump to: navigation, search

Mysql LPAD

From w3cyberlearnings

Contents

MySQL LPAD Function

This function returns left padded with a specific string. When the LENGTH is shorter than the STR length, it will return based on the LENGTH. However, when the LENGTH is longer than it will add the padstr to the left and return. See example for detail.

Syntax LPAD

  • Str: A String
  • Length: length of characters to be padded
  • PadStr: A pad string
LPAD(Str,length,padStr);

Example 1

mysql> SELECT LPAD('girl',5,'?');
+--------------------+
| LPAD('girl',5,'?') |
+--------------------+
| ?girl              |
+--------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT LPAD('lovely girl',5,'?');
+---------------------------+
| LPAD('lovely girl',5,'?') |
+---------------------------+
| lovel                     |
+---------------------------+
1 row in set (0.00 sec)

Related Links


Navigation
Web
SQL
MISC
References