Avatar of fb1990
fb1990
 asked on

Extracting Specific String

Hello Expert,

I need a code snippet that will help in extracting specific text from a string in oracle.  I have attached my sample data here.  I need to extract 2.2.1.0,2.2.1.0 and 2.2.3.8 in that order

diamond CU/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup
diamond CU/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup
diamond Credit Union/2.2.3.8 BatchID/com.diamond.banking00000 BatchPlatformGroup

Open in new window


Thanks in advance for your help!
Oracle Database

Avatar of undefined
Last Comment
fb1990

8/22/2022 - Mon
slightwv (䄆 Netminder)

Assuming that is three rows of data try this:
select regexp_substr(mycol,'[0-9.]+') from mytable;
slightwv (䄆 Netminder)

If that is one row in a table, try this:

select regexp_substr(mycol,'/([0-9.]+)',1,level,null,1) from mytable
connect by level <= regexp_count(mycol,'/[^/]+/');
Sean Stuber

If the pattern you are looking for is a series of 4 digits separated by a period

then try this

select regexp_substr(yourstring,'([0-9]\.){3}[0-9]',1,level) from yourtable
connect by regexp_substr(yourstring,'([0-9]\.){3}[0-9]',1,level)  is not null

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
fb1990

ASKER
thanks slightwv and sdstuber.  

The pattern that i am looking for is first 4 digit after the first back slash.  from this example diamond CU/2.2.1.0 example, i need to get 2.2.1.0
slightwv (䄆 Netminder)

Any of the posted code should do that.

To be 100% sure:  We still need to know if your sample data is 3 rows in the table or 1?
fb1990

ASKER
sorry... i did not answer that question.

my data is 3 rows.

Thanks.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
slightwv (䄆 Netminder)

Then try my fist post instead of the second.  My first post will fail if the credit union name can have a number in it.

Like this:
diamond 1 CU/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup

If that is a possibility, use sdstuber's.  Just remove the recursion.

select regexp_substr(yourstring,'([0-9]\.){3}[0-9]') from yourtable


Now that will fail if you can have data like:
diamond 1.1.1.1 CU/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup

If that is a possibility and you really need it after the slash, let us know.
fb1990

ASKER
i cannot have data like this diamond 1.1.1.1 CU/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup

But, i can have data like
diamond 1 CU/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup

or
diamond 1 Credit Union/2.2.1.0 BatchID/com.diamond.banking.0000 BatchPlatformGroup
slightwv (䄆 Netminder)

OK then, go with my altered version of what sdstuber posted.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Sean Stuber

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
fb1990

ASKER
Thank you slightwv nd sdstuber.  The solution provided by sdstuber worked like a charm