
- 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 to add a specific character to any 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)
- Related Articles
- How to add space before and after specific character using regex in Python?
- Replace the empty values from a MySQL table with a specific value
- How to add columns at specific position in existing table in MySQL?
- How to add space around table border in HTML?
- Add a character in the end to column values with MySQL SELECT?
- How to replace a character in a MySQL table?
- How to search for ^ character in a MySQL table?
- How to check an empty table already in a MySQL database?
- MySQL query to update a specific cell to be empty
- Add a character to a specific position in a string using Python
- How to add a column in a table in MySQL?
- How to add a column to a MySQL table in Python?
- Effective way to add integers based on table values in MySQL?
- How to exclude a specific row from a table in MySQL?
- How to search a MySQL table for a specific string?

Advertisements