[英]How to find a row where col have special characters or numbers (except hyphen,apostrophe and space) in Oracle SQL
I need to find rows where col have special characters or numbers (except hyphen,apostrophe and space) in Oracle SQL.我需要在 Oracle SQL 中找到 col 具有特殊字符或数字(连字符、撇号和空格除外)的行。
I am doing like below:我正在做如下:
SELECT *
FROM test
WHERE Name_test LIKE '%[^A-Za-z _]%'
But It is not working and I also need to exclude any apostrophe.但它不起作用,我还需要排除任何撇号。 Kindly help.
请帮忙。
If you need to find all rows where column have ONLY numbers and special characters (and you can specify all of required special characters):如果您需要查找列仅包含数字和特殊字符的所有行(并且您可以指定所有必需的特殊字符):
SELECT *
FROM test
WHERE regexp_like(Name_test, q['^[0-9'%#@]+$]')
as you can see you just need to add your special characters after 0-9.如您所见,您只需要在 0-9 之后添加特殊字符。 ^ - start $ - end
^ - 开始 $ - 结束
About format q'[SOMETHING]' please see TEXT LITERALS here: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA关于格式 q'[SOMETHING]' 请在此处查看文本文字: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Literals.html#GUID-492EAA-CB66 B2A6-112FB02248DA
If you need to find all rows where column have no alpha-characters:如果您需要查找 column 没有字母字符的所有行:
SELECT *
FROM test
WHERE regexp_like(Name_test, '^[^a-zA-Z]*$');
or SELECT * FROM test WHERE regexp_like(Name_test, '^\W*$');或 SELECT * FROM test WHERE regexp_like(Name_test, '^\W*$');
about \W - please see "Table 8-5 PERL-Influenced Operators in Oracle SQL Regular Expressions" here:关于 \W - 请在此处查看“Oracle SQL 正则表达式中的表 8-5 受 PERL 影响的运算符”:
https://docs.oracle.com/database/121/ADFNS/adfns_regexp.htm#ADFNS235 https://docs.oracle.com/database/121/ADFNS/adfns_regexp.htm#ADFNS235
I need to find rows where col have special characters or numbers (except hyphen, apostrophe and space [and presumably single quotes]) in Oracle SQL.
我需要在 Oracle SQL 中找到 col 具有特殊字符或数字(连字符、撇号和空格 [以及可能是单引号] 除外)的行。
You can use double single quotes to put a single quote in:您可以使用双单引号将单引号放入:
WHERE Name_test LIKE '%[^-A-Za-z _'']%'
However, this is not Oracle syntax.但是,这不是 Oracle 语法。 If the above works, then I would guess you are using SQL Server.
如果上述方法有效,那么我猜您正在使用 SQL 服务器。 In Oracle:
在 Oracle 中:
WHERE REGEXP_LIKE(Name_test, '[^A-Za-z _'']')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.