Solved

Remove Hyphens in Oracle SQL

Posted on 2016-09-09
5
63 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
  • 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 73

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 73

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 - query 23 61
SQL Sub-Query Help 22 62
PL SQL Developer 7 35
SQL Workhours Count beetween Workhours 3 17
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to recover a database from a user managed backup

777 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