LPAD & RPAD mysql string function

SELECT LPAD('plus2net',13,'**');
The output is here
*****plus2net
You can see we have plus2net of 8 characters long. To this we have added or Pad at left ( at starting ) so the resultant string is of total 13 chars length.
What if the required length is less than the original string?
SELECT LPAD('plus2net',2,'**');
The output is here
pl
This is first two chars of our input sting only.

RPAD string function to right pad string in MySQL

MySQL RPAD string function is used to pad strings from right. We will use this function along with select query but it can be used along with any other string commands.

Here are some examples of RPAD function
select rpad('plus2net',15,'*')
The output is here plus2net*******

We have added another string to right of our input string and the final output is of length 15 char. One more example is here
SELECT rpad( 'plus2net', 15, 'abc' )
Output of this is plus2netabcabca

What happens if we give less than the input string length.
SELECT rpad( 'plus2net', 5, 'abc' )
Output will be plus2 ( Up to 5 char only )
SQL String References LEFT side chars by using Query FIND_IN_SET

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com

    Post your comments , suggestion , error , requirements etc here





    SQL Video Tutorials










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer