这真的开始受伤了!
我正在尝试使用正则表达式条件在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.
我会很感激你能提供的任何东西。
以下作品:
select * 
  from dm_name 
  WHERE regexp_like(last_name, '([^A-Za-z ''-])');
我无法证明 SQL Developer 是否会喜欢它,因为我没有安装该产品。
分享并享受。
只需将单引号加倍即可转义。
所以
select *
  from dm_name
 where regexp_like(last_name, '[^A-Za-z ''-]')
   and batch_id = 'ATEST'
另请参见此sqlfiddle。注意,我在SQL开发人员中尝试了类似的查询,并且效果很好。
还要注意,这个工作的-性质必须是该组中的最后一个字符否则它试图找到该组SPACE来',而不是字符-。
| 归档时间: | 
 | 
| 查看次数: | 9272 次 | 
| 最近记录: |