[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Oracle: Finding / Parsing  numerical string out of text field

Posted on 2011-09-27
9
Medium Priority
?
427 Views
Last Modified: 2012-08-14
I have a table ie temp_memo which has one column called memo.

typical values are

"called number (123-456-7890) then spoke to bob with account number (123456)"

or

"account number 123456, number that dial was 1234567890 name was bob"

or

"account number 123456, number 123-456-7890 bob called to"

or

"bob called his number was (1234567890), caller id number is 123456"

Basically I want to create a script that isolates and populates on the phone number in the format
1234567890.

Ideally I would like to do in SQL but I have other tools at disposal such as excel.

Any help would be greatly appreciated.

Many thanks,
0
Comment
Question by:B_rider
[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
  • 6
  • 3
9 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 36711502
select regexp_substr(replace(memo,'-'),'[0-9]{10}') from temp_memo

I made the assumption that the phone number will be the only 10digit numeric substring

if that's not true, please explain what rules I can use to identify a phone number from other numbers
0
 

Author Comment

by:B_rider
ID: 36711558
Hi thanks sbstuber,
running:
select regexp_substr(replace(memo,'-'),'[0-9]{10}') from temp_memo_test

getting invalid column name for regexp_substr

running oracle 8i right now, think this is a versioning issue? if so is there anyway around?

Many Thanks,

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36711569
alternately,  if phone numbers will always be of the form 1234567890 or 123-456-7890

you could try....


 replace(regexp_substr(memo,'[0-9]{10}|([0-9]{3}-){2}[0-9]{4}'),'-')

this is less efficient, but more accurate if the pattern assumption above is true
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 74

Expert Comment

by:sdstuber
ID: 36711582
yes,  8i doesn't have regular expressions.


that's woefully out of date,  I highly recommend upgrading.

however, assuming that's not an immediate option I'll see what I can come up with
0
 

Author Comment

by:B_rider
ID: 36711615
yah I'm aware of the versioning problems and would need to sift through a yeah long hike through the jungle of IT buearcary to get it upgraded
many thanks for any attempts
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36711699
try this...

SUBSTR(replace(memo,'-'), INSTR(TRANSLATE(memo, '0123456789-', '0000000000'), '0000000000'), 10)

this assumes all phone numbers are of one of these formats: 1234567890 or 123-456-7890
it also assumes every line has a phone number
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36711707
note,  the 10 zeros is intentional even though there are 11 characters (10 digits plus hyphen)
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 36711720
if a phone number might not be present and you want to return NULL  then try this...



DECODE(
           INSTR(TRANSLATE(memo, '0123456789-', '0000000000'), '0000000000'),
           0, NULL,
           SUBSTR(REPLACE(memo, '-'),
                  INSTR(TRANSLATE(memo, '0123456789-', '0000000000'), '0000000000'),
                  10
                 ))

0
 

Author Closing Comment

by:B_rider
ID: 36712618
Amazing many thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

656 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