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

Need suggestion with Oracle REGEXP_REPLACE function

I am writing an update query where I need to update some values in a column using REGEXP_REPLACE function.

I had written the below query which works correctly.

update my_table_name
set column_name = REGEXP_REPLACE(column_name, '"MyValue":0', '"MyValue":2' )
WHERE column_id=1234;

However, after – "MyValue": it can be any number ranging from 0-9. So I am trying to have a check such that it match the first string i.e. – "MyValue": and anything number after that and if that matches the next value will be whatever I will be replacing it with.

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

Basically I need to match the string – "MyValue:" and any digit that comes after that in the REGEX_REPLACE

Any suggestions. Should I be using REGEX_REPLACE or something else. OR the regex needs some tweaking

>Solution :

You may use REGEXP_REPLACE as follows:

UPDATE my_table_name
SET column_name = REGEXP_REPLACE(column_name, '"MyValue":[0-9]', '"MyValue":2')
WHERE column_id = 1234;
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