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

How to extract a value inside column in certain pattern in oracle

I want to extract data in the format (465797,461396) from (‘,7809628#465797,7809628#461396,’) data. How can I do that?

>Solution :

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

[DBFiddle][1]

select
  ltrim(
    regexp_replace(
        ',7809628#465797,7809628#461396,'
       ,'[^#]*#(\d+),'
       ,',\1')
    ,','
  ) new_str
from dual;

Results:

NEW_STR
-------------
465797,461396

Regexp '[^#]*#(\d+),':

[^#]* – any number of any symbols except ‘#’
(\d+) – digits, one or more digits, () – marks it as a group
and comma after that.

So it finds (any symbols except #, then #, then one or more digits, then comma) and replaces all found substrings to comma and found "one or more digits"(the only group in the expression). Then ltrim removes extra comma in the beggining.
[1]: https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=f66505cd2746a1387e41ec91d6c7df3a

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