- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
MySQL query to replace part of string before dot
For this, use CONCAT() along with SUBSTRING_INDEX(). Let us first create a −
mysql> create table DemoTable1424 -> ( -> Value varchar(60) -> ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1424 values('567.78483733'); Query OK, 1 row affected (0.78 sec) mysql> insert into DemoTable1424 values('1023.45252443'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1424 values('7893322.5635543434'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1424 values('90944.665665'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select −
mysql> select * from DemoTable1424;
This will produce the following output −
+--------------------+ | Value | +--------------------+ | 567.78483733 | | 1023.45252443 | | 7893322.5635543434 | | 90944.665665 | +--------------------+ 4 rows in set (0.00 sec)
Following is the query to replace part of string before dot −
mysql> update DemoTable1424 -> set Value=concat('10000.',substring_index(Value ,'.',-1)); Query OK, 4 rows affected (0.13 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1424;
This will produce the following output −
+------------------+ | Value | +------------------+ | 10000.78483733 | | 10000.45252443 | | 10000.5635543434 | | 10000.665665 | +------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Replace part of string in MySQL table column?
- How to cut part of a string with a MySQL query?
- How to replace a part of the string (domain name after @) using MySQL?
- Replace dot with comma on MySQL SELECT?
- MySQL query to change a string by displaying only the part of string after underscore?
- Replace part of a string with another string in C++
- MySQL query to display a substring before a special character in a string
- MySQL query to replace a column value
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- Find and replace a part of URL records in MySQL?
- MySQL query to replace a string after the last / in a column with directory links?
- MySQL query to replace null value with empty string in several columns while fetching data
- MySQL query to fetch records before currentdate + 2 weeks?
- Does JavaScript have a method to replace part of a string without creating a new string?
- MySQL query to replace special characters from column value

Advertisements