简体   繁体   English

Oracle 查询以识别具有特殊字符的列

[英]Oracle query to identify columns having special characters

I'm trying to write a SQL query to return rows which has anything other than alphabets , numbers , spaces and following chars '.', '{','[','}',']' Column has alphabets like Ÿ , ¿我正在尝试编写一个Ÿ查询以返回除alphabetsnumbersspacesfollowing chars '.', '{','[','}',']'以外的任何行。 ¿

eg:- There's a table TEST with 2 columns - EmpNo and SampleText EmpNo is simple sequence and SampleText has values like例如:- 有一个包含 2 列的表TEST - EmpNoSampleText EmpNo是简单的序列, SampleText的值如下

('12345abcde','abcdefghij','1234567890','ab c d 1 3','abcd$%1234','%^*&^%$#$%','% % $ #  %','abcd 12}34{','MINNEAŸPOLIS','THAN ¿VV ¿A')

I want to write a query which should eliminate all rows which have even a single special character except .{[}] .我想编写一个查询,该查询应消除除.{[}]之外甚至具有单个特殊字符的所有行。 In above example, it should return EmpNo - 1,2,3,4 and 8 I tried REGEXP_LIKE but I'm not getting exactly what I need.在上面的例子中,它应该返回EmpNo - 1,2,3,4 and 8我试过REGEXP_LIKE但我没有得到我需要的。

Query I used:我使用的查询:

SELECT * FROM test 
WHERE REGEXP_LIKE(sampleText, '[^A-Z^a-z^0-9^[^.^{^}]' ,'x'); 

This is not ignoring blanks and I also need to ignore closing bracket ']'这不是忽略空白,我还需要忽略右括号 ']'

You can use regular expressions for this, so I think this is what you want:您可以为此使用正则表达式,所以我认为这就是您想要的:

select t.*
from test t
where not regexp_like(sampletext, '.*[^a-zA-Z0-9 .{}\[\]].*')

I figured out the answer to above problem.我想出了上述问题的答案。 Below query will return rows which have even a signle occurrence of characters besides alphabets, numbers, square brackets, curly brackets,s pace and dot.下面的查询将返回除字母、数字、方括号、大括号、空格和点之外的字符甚至出现一次的行。 Please note that position of closing bracket ']' in matching pattern is important.请注意,匹配模式中右括号“]”的 position 很重要。

Right ']' has the special meaning of ending a character set definition.右 ']' 具有结束字符集定义的特殊含义。 It wouldn't make any sense to end the set before you specified any members, so the way to indicate a literal right ']' inside square brackets is to put it immediately after the left '[' that starts the set definition在指定任何成员之前结束集合没有任何意义,因此在方括号内指示字面右 ']' 的方法是将其紧跟在开始集合定义的左 '[' 之后

SELECT * FROM test WHERE REGEXP_LIKE(sampletext,  '[^]^A-Z^a-z^0-9^[^.^{^}^ ]' );

They key is the backslash escape character will not work with the right square bracket inside of the character class square brackets (it is interpreted as a literal backslash inside the character class square brackets).它们的关键是反斜杠转义字符不能与字符 class 方括号内的右方括号一起使用(它被解释为字符 class 方括号内的文字反斜杠)。 Add the right square bracket with an OR at the end like this:在末尾添加带有 OR 的右方括号,如下所示:

select EmpNo, SampleText
from test 
where NOT regexp_like(SampleText, '[ A-Za-z0-9.{}[]|]');

Compare the length using lengthB and length function in oracle.在oracle中使用lengthB和长度function比较长度。

SELECT * FROM test WHERE length(sampletext) <> lengthb(sampletext)

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

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