简体   繁体   English

Oracle SQL查询以查找字符串中是否存在字符

[英]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. 我正在使用oracle数据库,并尝试找出当字符串上存在特殊字符(',`,(,))时应返回结果的查询。

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? 是否有任何函数/方法可用来获取此结果?

You can use regular expressions and check all special characters with one condition: 您可以使用正则表达式并使用一种条件检查所有特殊字符:

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

没有正则表达式的老派风格

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM