Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Extracting Specific String

Posted on 2016-07-21
11
Medium Priority
?
79 Views
Last Modified: 2016-07-21
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
Comment
Question by:fb1990
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 77

Expert Comment

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

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41723152
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
 
LVL 74

Expert Comment

by:sdstuber
ID: 41723300
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
Technology Partners: 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!

 
LVL 1

Author Comment

by:fb1990
ID: 41723328
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
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41723335
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
 
LVL 1

Author Comment

by:fb1990
ID: 41723417
sorry... i did not answer that question.

my data is 3 rows.

Thanks.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41723427
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
 
LVL 1

Author Comment

by:fb1990
ID: 41723562
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
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41723565
OK then, go with my altered version of what sdstuber posted.
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 41723566
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
 
LVL 1

Author Closing Comment

by:fb1990
ID: 41724014
Thank you slightwv nd sdstuber.  The solution provided by sdstuber worked like a charm
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question