Aravindhan
Aravindhan

Reputation: 3626

Oracle SQL Query to find the existence of characters in string

I am using oracle database and trying to find out the query which should return the result when there is a special character(',`,(,)) exist on the string.

I am trying something like this,

select username from users where username like (',`,~,(,));

I tried to achieve the same using the below query,

select username from users where (username like '%`%' OR username like '%~%');

It doesn't consider the second condition and returns the value to the first condition only.

Is there any function/methods using which this result can be fetched?

Upvotes: 0

Views: 3734

Answers (2)

Dr Y Wit
Dr Y Wit

Reputation: 2020

Old school style without regexp

where length(translate(username, '_''`~()', '_')) <> length(username)

Upvotes: 0

pablomatico
pablomatico

Reputation: 2242

You can use regular expressions and check all special characters with one condition:

SELECT username 
FROM users 
WHERE regexp_instr(username,'[''`\(\)]') > 0

Upvotes: 1

Related Questions