Finding strings with special characters in oracle

I want to find strings that contain double ampersands %% and double underscores __ and amp and underscore together

create table dummy
(name varchar2(100));

insert into dummy values ('abc_def_ghi_klo');
insert into dummy values ('abc%def%_klo');
insert into dummy values ('abc%def%__klo');
insert into dummy values ('abc%def%_%%klo');
gram77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
By 'double' do you mean side by side or just that it has two or more somewhere?
0
sdstuberCommented:
select * from dummy where regexp_like(name,'[%_]{2}')
0
slightwv (䄆 Netminder) Commented:
If side by side try:
select name from dummy where instr(name,'%%') > 0 or instr(name,'__') > 0;
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

sdstuberCommented:
you said "ampersand" above but you showed percent '%'  if you meant ampersand then

select * from dummy where regexp_like(name,'[&_]{2}')
0
awking00Commented:
See attached.
select name from dummy
where regexp_like(name,'%%|__|%_');

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sdstuberCommented:
extending on awking00's idea   missed the "_%" possibility


select name from dummy
where regexp_like(name,'%%|__|%_|_%');

that's why I suggested the  "[%_]{2}"  pattern above,
 it will cover all permutations for me.  but just 2, it's not too difficult to just list them all

0
awking00Commented:
sdstuber,
I thought about it but wasn't sure that the "_%" possibility was being considered since the asker indicated "and amp [sic] and underscore together."
0
sdstuberCommented:
fair enough  :)

and if it is the case that _% is not legal, then my first (and followup) post would be incorrect
0
paquicubaCommented:
sdstuber,
Yours works like this:
regexp_like(name,'[%|_]{2}')
0
sdstuberCommented:
paquicuba,

no
regexp_like(name,'[%|_]{2}')  

would search for two-character combinations of the three characters %,  |, and _

if you want to use "or" operator you would use () instead of []

regexp_like(name,'(%|_){2}')


0
sdstuberCommented:
so, given the sample data above

regexp_like(name,'[%|_]{2}')    would "appear" to work, but would really be false-postives since it includes the possibility of "aaaa|%"  which would not be correct
0
paquicubaCommented:
Oops! You're right. I just copied your code w/o noticing the brackets. My point is that your idea will work by introducing the vertical pie ( | ) opeartor within the grouping ( ) operator.
0
sdstuberCommented:
the original would work too, and the (%|_) will also work but they have the same caveat mentioned to awking00 above
0
gram77Author Commented:
insert into dummy values ('abc__def%%'); --I want to see this string
insert into dummy values ('abc__def%%ghi%_jkl'); --and not this string in the result

Now i want to see the data which has only __ (2 underscore) and %% (2 ampersands) in it, and nothing else
0
sdstuberCommented:
if you are changing the question you should close this one and open a new one
0
gram77Author Commented:
Excellent
0
gram77Author Commented:
Thank you all for your efforts, awking00 solution was the simplest and most elegant so i chose it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.