[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 83
  • Last Modified:

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!
0
fb1990
Asked:
fb1990
  • 5
  • 4
  • 2
1 Solution
 
slightwv (䄆 Netminder) Commented:
Assuming that is three rows of data try this:
select regexp_substr(mycol,'[0-9.]+') from mytable;
0
 
slightwv (䄆 Netminder) Commented:
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,'/[^/]+/');
0
 
sdstuberCommented:
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

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
fb1990Author Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
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?
0
 
fb1990Author Commented:
sorry... i did not answer that question.

my data is 3 rows.

Thanks.
0
 
slightwv (䄆 Netminder) Commented:
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.
0
 
fb1990Author Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
OK then, go with my altered version of what sdstuber posted.
0
 
sdstuberCommented:
then

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

will work


what that search does is:

find the first set of 3 digits followed by a period  (for example:   1.2.3.)
that is then followed by another digit   (1.2.3.4)

so,

2.2.1.0  would be found
1 would be skipped
1234 would be skipped
1.2.3  would be skipped
1.2.3.  would be skipped
1..2.3.  would be skipped
1.2.3.x  would be skipped
12.34.56.78  would be skipped

is that what you want?
0
 
fb1990Author Commented:
Thank you slightwv nd sdstuber.  The solution provided by sdstuber worked like a charm
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now