Solved

Using oracle's Regexp to return fields that are alphanumeric only

Posted on 2011-03-19
6
867 Views
Last Modified: 2012-05-11
Hello,

I am having a poblem using regexp to return rows where the searched column has alphanumeric data.  It must contain a mix of characters and numbers and NOT only alpha characters and NOT only digits. So for example, a table with the column last_name contains

LAST_NAME
Brown
Ja2k
1Long
12345

I want the search to return rows with Ja2k and 1Long because it has a mix of digits and alphas in any occurance.  All alphas and all digits are rejected

The following does not work as required:

select * from tablea
where regexp_like(last_name, '^[[:alnum:]].+[[:alpha:]]*$' )
0
Comment
Question by:klyles95
  • 3
  • 2
6 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 35173150
Try:
Regexp_like(last_name,'([0-9]+[A-Za-z]+[a-zA-Z0-9]*)|([a-zA-Z]+[0-9]+[a-zA-Z0-9]*)
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 35173503
same idea, slightly simplified

Regexp_like(last_name,'([0-9]+[A-Za-z]+|[a-zA-Z]+[0-9]+)[a-zA-Z0-9]*')
0
 

Author Closing Comment

by:klyles95
ID: 35173857
Thank you slightwv.  Worked like a charm
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

Expert Comment

by:sdstuber
ID: 35173967
already closed but even simpler...


Regexp_like(last_name,'([0-9]+[A-Za-z]|[a-zA-Z]+[0-9])[a-zA-Z0-9]*')
0
 

Author Comment

by:klyles95
ID: 35182228
Thank you sdstuber.  This works too!
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 35182593
actually,  all of the above are incorrect

they will all give a false positive for strings like this...

'12a!bc~34*xyz'

try this instead...

REGEXP_LIKE(last_name, '^([0-9]+[A-Za-z]|[a-zA-Z]+[0-9])[a-zA-Z0-9]*$')


you could add ^ and $ to the others as well
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now