Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Extract String

slider rulesNov 22 2021 — edited Nov 22 2021

Hi,
I am using Oracle 12.1.2. I want to extract the value from the strings below that are before the numbers and hyphen
For example below are strings and required output
ABC-123-561944625-GGG_3
required output - ABC
yyyy-land-tm-942473-dl_hhh_5
required output - yyyy-land-tm
hjdhgjfhgj-130909-wtygj_jhgkj_2
required output - hjdhgjfhgj
mmmm-hytc-tm-yy-942473-dl_hhh_5
required output - mmmm-hytc-tm-yy
sjg-099-wtygj_jhgkj_111
required output - sjg
create table t1 (tst VARCHAR2(80));
insert into t1 values('mmmm-hytc-tm-yy-942473-dl_hhh_5');
insert into t1 values('hjdhgjfhgj-130909-wtygj_jhgkj_2');
insert into t1 values('yyyy-land-tm-942473-dl_hhh_5');
insert into t1 values('ABC-123-561944625-GGG_3');
insert into t1 values('sjg-099-wtygj_jhgkj_111');

Results:
mmmm-hytc-tm-yy
hjdhgjfhgj
yyyy-land-tm
ABC
sjg

Which function can help achieve the above?

Comments
Post Details
Added on Nov 22 2021
2 comments
240 views