Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove dots and commas from numbers in MySQL database

In a Wordpress MySQL database, in wp_postmeta table, there are most rows with meta_key='price' and with meta_value='XXX' where XXX is a number. The meta_value is a long text field. The numbers stored in it have a different shape some are stored with a dot, meaning thousand (10.000 means ten thousand) others are stored with a comma, meaning hundredth (10,00 means ten). How to remove dots and comma so to have a pure number, without hundredth? In other words, 100.000 should be 100000 and 10,00 should be 10 Thank you in advance for your answers!

like image 390
Avionicom Avatar asked Feb 02 '26 07:02

Avionicom


1 Answers

Try a global REPLACE function

UPDATE wp_postmeta
SET meta_value = REPLACE(REPLACE(meta_value,',00',''),'.','')
WHERE meta_key='price';
like image 161
RolandoMySQLDBA Avatar answered Feb 04 '26 00:02

RolandoMySQLDBA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!