-1

I am trying to extract the number from the row.

i am trying this in Oracle 11G

CREATE TABLE test1
(
COL_NAME VARCHAR2(100)
);


insert into test1 values ('DWH_SCHEMA_BI.AB_25_BC_ORDER_STATUS');


select COL_NAME, REGEXP_REPLACE(COL_NAME, '^([A-Z0-9$]{17,})_.*', '\17') as BEGINNING from TEST1
and COL_NAME='DWH_SCHEMA_BI.AB_25_BC_ORDER_STATUS'

EXISTING RESULT

COL_NAME                             BEGINNING
DWH_SCHEMA_BI.AB_25_BC_ORDER_STATUS  DWH_SCHEMA_BI.AB_25_BC_ORDER_STATUS

EXPECTED RESULT

COL_NAME                             BEGINNING
DWH_SCHEMA_BI.AB_25_BC_ORDER_STATUS  25

Total Patterns

DWH_SCHEMA_BI.AB_25_BC_ORDER_STATUS
DWH_SCHEMA.ABC_02_BC_ORDER_STATUS
DWH_BID.ABC_11_BC_ORDER_STATUS

Please note i have total 3 patterns, how to achieve the desired result , seems my REGEXP logic is not working as per the EXPECTED RESULTS

https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=8aafffde010ae586f8a79974ee1ff140

Data2explore
  • 452
  • 6
  • 16

1 Answers1

2

Use regexp_substr():

select t1.*,
       regexp_substr(col_name, '[0-9]+')
from test1 t1;

Here is a db<>fiddle.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786