Solved

Remove Hyphens in Oracle SQL

Posted on 2016-09-09
5
175 Views
Last Modified: 2016-09-09
I have a ssn field.
The field has hyphens in it.
Ex. xxx-xx-xxxx

How can I just extract the numbers without the hyphens?
0
Comment
Question by:metalteck
[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
  • 3
  • 2
5 Comments
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 250 total points
ID: 41791594
select replace(ssn,"-",null)
0
 
LVL 32

Expert Comment

by:awking00
ID: 41791660
Depending on your version, I believe you can also just do replace(ssn,'-')
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 250 total points
ID: 41791663
if it might have other non-numeric characters (spaces, commas, periods, hyphens, etc.)

then try  

regexp_replace(ssn,'[^0-9]')
0
 
LVL 32

Expert Comment

by:awking00
ID: 41791678
It's quite common to express ssn in the xxx-xx-xxxx format and I suspect eliminating the hyphens may be all that's needed. There is also something called a PTIN (stands for preparer tin) that begins with the letter "P" which wouldn't be retained if just the digits are retrieved.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 41791682
if you need to preserve a "P" as well as digits and exclude all others then simply add P to the "keep" list.

regexp_replace(ssn,'[^0-9P]')
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

635 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