
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we update MySQL table after padding a string with the values of the column?
We can update MySQL table after padding a string with the values of a column by using LPAD() or RPAD() function along with UPDATE clause. Following the example from ‘examination_btech’ table will make it clearer −
Example
Suppose if we want to append the values, in last, of column course with the string ‘(CSE)’ and want to update the table too then it can be done with the help of the following query −
mysql> Update examination_btech set course = RPAD(Course, 11,'(CSE)'); Query OK, 10 rows affected (0.16 sec) mysql> Select * from examination_btech; +-----------+----------+-------------+ | RollNo | Name | Course | +-----------+----------+-------------+ | 201712001 | Rahul | B.tech(CSE) | | 201712002 | Raman | B.tech(CSE) | | 201712003 | Sahil | B.tech(CSE) | | 201712004 | Shalini | B.tech(CSE) | | 201712005 | Pankaj | B.tech(CSE) | | 201712006 | Mohan | B.tech(CSE) | | 201712007 | Yash | B.tech(CSE) | | 201712008 | digvijay | B.tech(CSE) | | 201712009 | Gurdas | B.tech(CSE) | | 201712010 | Preeti | B.tech(CSE) | +-----------+----------+-------------+ 10 rows in set (0.00 sec)
From the above result set, it is clear that ‘(CSE)’ has been padded at last with the values of column ‘course’ and the table also got updated.
Similarly, with the help of LPAD() function, we can pad the string in starting and update the table.
- Related Articles
- How can we update MySQL table after removing a particular string from the values of column?
- How can I update MySQL table after quoting the values of a column with a single quote?
- How can we update values in a MySQL table?
- How can we update any value in MySQL view as we can update the values in MySQL table?
- How can we update the values in one MySQL table by using the values of another MySQL table?
- How can we use LPAD() or RPAD() functions with the values in the column of a MySQL table?
- MySQL regular expression to update a table with column values including string, numbers and special characters
- How can we use MySQL EXPORT_SET() function with column of a table?
- How can we update columns values on multiple rows with a single MySQL UPDATE statement?
- How to update a MySQL table by swapping two column values?
- How can we count a number of unique values in a column in MySQL table?
- How can we add values into the columns of a MySQL table?
- How can we subtract values in MySQL table with the help of LEFT JOIN?
- How can we remove a column from MySQL table?
- How can we modify column/s of MySQL table?

Advertisements