
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Specific Character to Empty Space in MySQL Table Values
For this, use REPLACE() function and replace empty space with the character. Let us first create a table −
mysql> create table DemoTable (Subject text); Query OK, 0 rows affected (0.86 sec)
Example
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Java in depth'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Data Structure and Algorithm'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+------------------------------+ | Subject | +------------------------------+ | Introduction to MySQL | | Java in depth | | Data Structure and Algorithm | +------------------------------+ 3 rows in set (0.00 sec)
Following is the query to replace empty space −
mysql> SELECT *,REPLACE(Subject,' ','_') as Subject_Name from DemoTable;
Output
+-------------------------------+------------------------------+ | Subject | Subject_Name | +-------------------------------+------------------------------+ | Introduction to MySQL | Introduction_to_MySQL | | Java in depth | Java_in_depth | | Data Structure and Algorithm | Data_Structure_and_Algorithm | +-------------------------------+------------------------------+ 3 rows in set (0.00 sec)
Advertisements