Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exracting substring from given string

I have data as following

1)MAXO_INSTR_INTERFACE    
2)MAXIS_VENDOR_INTERFACE
3)MAXIMOS_EMPS_INTERFACE2

I need to extract String which is located between both underscores in PL/SQL as

INPUT                    EXPECTED OUTPUT
------------------------ ---------------
MAXO_INSTR_INTERFACE     INSTR   
MAXIS_VENDOR_INTERFACE   VENDOR  
MAXIMOS_EMPS_INTERFACE2  EMPS

I have tried with substring function but i am unable to perform accurately.

like image 503
Maddy Avatar asked Mar 18 '26 19:03

Maddy


1 Answers

A slightly easier regular expression:

SQL> with t as
  2  ( select 'maxo_instr_interface' as txt from dual union all
  3    select 'maxis_vendor_interface' from dual union all
  4    select 'maximos_emps_interface2' from dual
  5  )
  6  select txt
  7       , regexp_substr(txt,'[^_]+',1,2)
  8    from t
  9  /

TXT                     REGEXP_SUBSTR(TXT,'[^_]
----------------------- -----------------------
maxo_instr_interface    instr
maxis_vendor_interface  vendor
maximos_emps_interface2 emps

3 rows selected.

Regards,
Rob.

like image 111
Rob van Wijk Avatar answered Mar 21 '26 10:03

Rob van Wijk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!