Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Oracle regex to remove every but not last occurrence of dot

I need regex to remove dots from a number, but not the last one.

What I’d like to do:

100.000.10 -> 100000.10

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried with:

SELECT REGEXP_REPLACE ('100.100.10', '\.(?![^.]+$)|[^0-9.]','') FROM dual;

But it return 100.100.10

>Solution :

You do not need (slow) regular expression and can use (much faster) simple string functions:

SELECT REPLACE(SUBSTR(value, 1, INSTR(value, '.', -1) - 1), '.')
       || SUBSTR(value, INSTR(value, '.', -1)) AS updated_value
FROM   table_name;

Which, for the sample data:

CREATE TABLE table_name (value) AS
SELECT '100.000.10' FROM DUAL;

Outputs:

UPDATED_VALUE
100000.10

fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading