您可以使用以下查询来包括除 space, - and ' ``` SQL> with tbl(name) as ( 2 select 'Kevin#123' from dual union 3 select 'bob@jr' from dual union 4 select 'mike$dr' from dual union 5 select 'Alex-jr' from dual union 6 select 'Brian jr' from dual union 7 select 'Brian)jr' from dual union 8 select 'Robert''jr' from dual 9 ) 10 select * 11 from tbl 12 where regexp_like(name, '[^[a-z]|[A-Z]|[:space:]|[:cntrl:]|/]') 13 and not regexp_like(name,'[- '']');
NAME
Brian)jr -- see this is included Kevin#123 bob@jr mike$dr
SQL> with test (col) as
2 (select 'Robert@jr23' from dual union all
3 select 'Kevin#123' from dual union all
4 select 'bob@jr' from dual union all
5 select 'mike$dr' from dual union all
6 select 'Alex-jr' from dual union all
7 select 'Robert''jr' from dual union all
8 select 'Brian jr' from dual
9 )
10 select col
11 From test
12 where regexp_replace(col, '[[:alpha:]]|[[:digit:]]|-|''', null) is not null;
COL
-----------
Robert@jr23
Kevin#123
bob@jr
mike$dr
Brian jr
SQL>
SQL> with test (id, col) as
2 (select 1, 'Robert@jr23' from dual union all
3 select 2, 'Kevin#123' from dual union all
4 select 3, 'bob@jr' from dual union all
5 select 4, 'mike$dr' from dual union all
6 select 5, 'Alex-jr' from dual union all
7 select 6, 'Robert''jr' from dual union all
8 select 7, 'Brian jr' from dual union all
9 select 8, 'Brian10' from dual
10 )
11 select col,
12 regexp_replace(col,
13 '[[:alpha:]]|[[:digit:]]|[[:space:]]|-|''', null) result
14 from test;
COL RESULT
----------- ----------
Robert@jr23 @
Kevin#123 #
bob@jr @
mike$dr $
Alex-jr
Robert'jr
Brian jr
Brian10
8 rows selected.
SQL>
SQL> with test (id, col) as
2 (select 1, 'Robert@jr23' from dual union all
3 select 2, 'Kevin#123' from dual union all
4 select 3, 'bob@jr' from dual union all
5 select 4, 'mike$dr' from dual union all
6 select 5, 'Alex-jr' from dual union all
7 select 6, 'Robert''jr' from dual union all
8 select 7, 'Brian jr' from dual union all
9 select 8, 'Brian10' from dual
10 )
11 select id, col
12 from test
13 where regexp_replace(col, '[[:alpha:]]|[[:space:]]|-|''', '')
14 is not null;
ID COL
---------- -----------
1 Robert@jr23
2 Kevin#123
3 bob@jr
4 mike$dr
8 Brian10
SQL>
3条答案
按热度按时间zpf6vheq1#
你需要使用
not
与要排除的值匹配的模式。否则,您将匹配包含不在排除列表中的任何字符的字符串,排除列表是所有字符。编辑:添加了
regex_like
条件,以确保值包含字母或数字和“特殊字符”,这里指的是既不是字母、数字也不是空格的字符,'
或者-
.lnlaulya2#
您可以使用以下查询来包括除
space, - and '
```SQL> with tbl(name) as (
2 select 'Kevin#123' from dual union
3 select 'bob@jr' from dual union
4 select 'mike$dr' from dual union
5 select 'Alex-jr' from dual union
6 select 'Brian jr' from dual union
7 select 'Brian)jr' from dual union
8 select 'Robert''jr' from dual
9 )
10 select *
11 from tbl
12 where regexp_like(name, '[^[a-z]|[A-Z]|[:space:]|[:cntrl:]|/]')
13 and not regexp_like(name,'[- '']');
NAME
Brian)jr -- see this is included
Kevin#123
bob@jr
mike$dr
SQL>
bfhwhh0e3#
一种选择是用
NULL
,剩下的无效:我不知道你想得到什么结果。下面是一些例子,展示了这样一个正则表达式的结果;因此,您希望获得哪些ID?
你的一条评论说:
选择必须有特殊字符或数字的客户名称(空格、连字符和撇号除外)
这意味着数字和特殊字符应该被视为“相等”。如果是这样,这有帮助吗?