Solved

Oracle SQL - Removing Alphanumeric Characters from Strings

Posted on 2013-11-19
2
1,189 Views
Last Modified: 2013-11-19
Hi,

I'm trying to search in my name field for the records with no alphanumeric values.
I want to find the records with only null value or only special characters such as . , ? ! * % #.

For example,

ID       Name
----     ----------
1         James Brown??..
2
3         ...
4        >,*..??
5        1/James Brown***

Then, I want my code to return only ID 2,3,4 and not 1,5.
Also, I need to put this check in a case statement, rather than in a where clause.

Can you please help me how I can write this check using regexp_like or regexp_replace?

Thank you!
0
Comment
Question by:iamnamja
2 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 300 total points
ID: 39659345
Try this:

drop table tab1 purge;
create table tab1 ( id number, col1 varchar2(100));

insert into tab1 values(1,'James Brown??..');
insert into tab1 values(2, null);
insert into tab1 values(3,'...');
insert into tab1 values(4,'>,*..??');
insert into tab1 values(5,'1/James Brown***');
commit;

select id from tab1 where not regexp_like(col1,'[A-Za-z0-9]') or col1 is null;

Open in new window

0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 200 total points
ID: 39659359
select id from your_table where regexp_like(name,'^[.,?!*%#]+$') or name is null;

simply add whatever characters you want into the [] list
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

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…
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 explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

803 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