We know that the data can be changed inside a field by using update command.
In this article I will guide you to replace part of the data without changing the entire data of the field. For this we will use replace command to replace a part of the contents in a fields. We will use the following table (Employee) for illustration purpose:
Name |
Department |
Amit |
.NET Tech |
Sumit |
Java Tech |
Anit |
PHP Tech |
Now we will use replace in query to change the department by using below query.
UPDATE Employee SET Department=REPLACE(Department, 'Tech', 'Technology')
The output of the query will be as below :
Name |
Department |
Amit |
.NET Technology |
Sumit |
Java Technology |
Anit |
PHP Technology |
We can also use the WHERE clause if we want to do replace for a selected records. For example if we want to do the replace operation for employee Amit , we will use the below query :
UPDATE Employee SET Department=REPLACE(Department, 'Tech', 'Technology') WHERE Name='Amit'
0 Comment(s)