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

Extract date and name in Oracle sql

I have prg_tbl table in which i insert filenames from directory in the column Filename and values are stored in column Filename as :

TRG_jira_creditentity_20220426.csv
TRG_jira_CRL_Boni_20220426.csv
TRG_jira_CRL_Branchen_20220426.csv
TRG_jira_CRL_Counterparty_20220426.csv
TRG_jira_CRL_KNE_20220426.csv
TRG_jira_CRL_Länder_20220426.csv

In one select query i want to extract date from this rows for example '20220426'. And in another select query i want to extract filename for example 'TRG_jira_creditentity_'.

I am not sure how to do this using select query as the dates from filename gets changes but the prefix which is part of filename it remains static for example 'TRG_jira_creditentity_'.

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

>Solution :

One option is to use REGEXP_REPLACE() function such as

SELECT REGEXP_REPLACE(filename,'^(.*_)([^.]*).*','\2') AS col1,
       REGEXP_REPLACE(filename,'[^_]+$') AS col2       
  FROM prg_tbl

Demo

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