2

我正在尝试提出一个脚本,我们可以使用它来定位数据列中可能存在的任何特殊字符,除了句点、破折号或下划线,并使用变量。

我的数据 - 员工表:

---------------------------------------------------------
 ID |   LASTFIRST | LAST_NAME | FIRST_NAME | MIDDLE_NAME
---------------------------------------------------------
 57 | Miller, Bob |    Miller |   &^$#*)er |      NULL
 58 |  Smith, Tom |     Smith |        Tom |         B
 59 |  Perry, Pat |     Perry |         P. |    Andrew

我的脚本:

VAR spchars VARCHAR  
spchars := '!#$%&()*+/:;<=>?@[\\\]^`{}|~'

select *
  from (select dcid, LastFirst, Last_Name, First_Name, middle_name,    
          CASE WHEN REGEXP_LIKE(First_Name, '[ || spchars || ]*$' )
               THEN '0' ELSE '1' END AS FNSPC 
          from employees)
 where FNSPC = '0';
 /

并返回所有行。

知道我在这里做错了什么吗?我只想选择 Bob Miller 的行。

4

1 回答 1

2

正则表达式,Schmegexp!;-)

select * from employees
where translate (first_name, 'x!#$%&()*+/:;<=>?@[\]^`{}|~', 'x') != first_name;

这会将所有特殊字符转换为无,即从字符串中删除它们 - 从而更改字符串值。

'x' 只是一个技巧,因为translate如果第三个参数为空,它就不能按你的意愿工作。

于 2015-11-19T16:59:57.693 回答