- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we stuff a string with another one using MySQL functions?
MySQL have two functions namely LPAD() and RPAD() with the help of which we can stuff a string with another string.
LPAD() function, as the name suggests, left stuff a string with another string. Following is the syntax for using it in MySQL −
Syntax
LPAD(original_string, @length, pad_string)
Here,
- original_string is the string in which we stuff another string.
- @length is the total length of string returned after stuffing.
- Pad_string is the string which is to be stuffed with original_string.
Example
mysql> SELECT LPAD('tutorialspoint',18,'www.'); +----------------------------------+ | LPAD('tutorialspoint',18,'www.') | +----------------------------------+ | www.tutorialspoint | +----------------------------------+ 1 row in set (0.00 sec)
RPAD() function, as the name suggests, right stuff a string with another string. Following is the syntax for using it in MySQL −
Syntax
RPAD(original_string, @length, pad_string)
Here,
- original_string is the string in which we stuff another string.
- @length is the total length of string returned after stuffing.
- Pad_string is the string which is to be stuffed with original_string.
Example
mysql> SELECT RPAD('www.tutorialspoint',22,'.com'); +--------------------------------------+ | RPAD('www.tutorialspoint',22,'.com') | +--------------------------------------+ | www.tutorialspoint.com | +--------------------------------------+ 1 row in set (0.06 sec)
Advertisements