您的位置:首页 > 其它

COOKBOOK 14.6 搜索字母数字混合的字符串

2013-08-09 21:07 134 查看
cookbook原方法有错误,示例如下

SQL> with v as (
2  select 'ClassSummary' strings from dual union
3  select '3453430278'           from dual union
4  select 'findRow 55'           from dual union
5  select '1010 switch'          from dual union
6  select '333'                  from dual union
7  select 'threes'               from dual union
8  select '#*'               from dual
9  )
10  select strings
11    from (select strings,
12                 translate(strings,
13                           'abcdefghijklmnopqrstuvwxyz0123456789',
14                           rpad('#', 26, '#') || rpad('*', 10, '*')) translated
15            from v) x
16   where instr(translated, '#') > 0
17     and instr(translated, '*') > 0
SQL> /

STRINGS
------------
#*
1010 switch
findRow 55


#改为a,*改为0即可出正确结果

SQL> with v as (xxx)
10  select strings,translated
11    from (select strings,
12                 translate(strings,
13                           'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
14                           rpad('a', 52, 'a') || rpad('0', 10, '0')) translated
15            from v) x
16   where instr(translated, 'a') > 0
17     and instr(translated, '0') > 0
18  /

STRINGS      TRANSLATED
------------ ------------------------------------------------
1010 switch  0000 aaaaaa
findRow 55   aaaaaaa 00


其正则实现方式如下

with v as (xxx)
select strings
from v
where regexp_like(v.strings,'[[:alpha:]]')
and regexp_like(v.strings,'[0-9]');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐