5

这真的开始疼了!

我正在尝试使用正则表达式条件在 Oracle 开发人员中编写查询

我的目标是找到所有包含名称中不常见的字符的姓氏(非字母、空格、连字符和单引号)

即我需要找到

J00ls
McDonald "Macca"
Smithy (Smith)

并没有找到

Smith
Mckenzie-Smith
El Hassan
O'Dowd

我现在的查询是

select * from dm_name 
WHERE regexp_like(last_name, '([^A-Za-z -])')
and batch_id = 'ATEST';

它排除了除单引号之外的所有预期内容。在放置单引号字符时,Oracvel SQL Develoepr 解析器将其视为文字。

我试过了:

\' -- but got a "missing right parenthesis" error
||chr(39)|| -- but the search returned nothing
'' -- negated the previous character in the matching group e.g. '([^A-Za-z -''])' made names with '-' return.

我会很感激你能提供的任何东西。

4

2 回答 2

5

Just double the single quote to escape your quote.

So

select *
  from dm_name
 where regexp_like(last_name, '[^A-Za-z ''-]')
   and batch_id = 'ATEST'

See also this sqlfiddle. Note, I tried a similar query in SQL developer and that worked as well as the fiddle.

Note also, for this to work the - character has to be the last character in the group as otherwise it tries to find the group SPACE to ' rather than the character -.

于 2013-10-21T00:08:32.437 回答
4

以下作品:

select * 
  from dm_name 
  WHERE regexp_like(last_name, '([^A-Za-z ''-])');

请参阅此 SQLFiddle

SQL Developer 是否喜欢它是我无法证明的,因为我没有安装该产品。

分享和享受。

于 2013-10-20T23:59:59.063 回答