现在的位置: 首页 > 综合 > 正文

[每日一题] OCP1z0-047 :2013-08-22 正则表达式—[^Ale|ax.r$]‘………………………………92

2013年01月09日 ⁄ 综合 ⁄ 共 2039字 ⁄ 字号 评论关闭

转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/10202115

 

正确答案:DE

 

一、Oracle正则表达式的相关知识点

'[^Ale|ax.r$]':

^:匹配行的开始字符

$:匹配行的结束字符

[]:方括号表示指定一个匹配列表,该列表匹配列表中显示的任何表达式。

[^]:同上面相反,非匹配列表表达工。

.:匹配任意一个字符(除了NULL)

|:替换元字符;结束第一个选项并开始下一个替换表达式

[^Ale|ax.r$]'中^表示只匹配不在集合{'A','l','e','|','a','x','.','r','$'}中的字符, 此处的'|'、'.'、'$'只是表示普通的字符,而非匹配符。字符串: [Ale|ax.r$] 匹配Alex,Alax ,Alxer ,A,l,e,a.............

不包含 A l e a x r的串,等效于[^Aleaxr],只要在串里面找到符合条件的字符(哪怕就一个)就算匹配。

先来看一下答案:

gyj@MYDB> with gyj_test as (
  2   select 'Alex' name from dual
  3   union all
  4   select 'Alax' name from dual
  5   union all
  6   select 'Alxer' name from dual
  7   union all
  8   select 'Alexender' name from dual
  9   union all
 10   select 'Alexendar' name from dual)
 11   select * from gyj_test where  regexp_like(name,'[^Ale|ax.r$]');

NAME
---------
Alexender
Alexendar

 

二、分析:

 '^Ale|ax.r$'――表示匹配Ale或ax开头的字符串,.表示任一字符。

gyj@MYDB> create table gyj_test1 (id int,name varchar2(20));

Table created.

gyj@MYDB> insert into gyj_test1 values(1,'Alex');

1 row created.

gyj@MYDB> insert into gyj_test1 values(2,'Alax');

1 row created.

gyj@MYDB> insert into gyj_test1 values(3,'Alxer');

1 row created.

gyj@MYDB> insert into gyj_test1 values(4,'Alexender');

1 row created.

gyj@MYDB> insert into gyj_test1 values(4,'Alexendar');

1 row created.

gyj@MYDB> commit;

Commit complete.

 

gyj@MYDB> select * from gyj_test1 where regexp_like(name,'^Ale|ax.r$');

        ID NAME
---------- --------------------
         1 Alex
         4 Alexender
         4 Alexendar

 

 

三、以上的SQL语句等价于:

gyj@MYDB> select * from gyj_test1 where  regexp_like(name,'^Ale')
  2   union all
  3   select * from gyj_test1 where  regexp_like(name,'ax.r$');

        ID NAME
---------- --------------------
         1 Alex
         4 Alexender
         4 Alexendar

 

四、^出现在[]中表示否定,查询的结果集里含有不是中括号里的字母Aleaxr

gyj@MYDB> select * from gyj_test1 where  regexp_like(name,'[^Ale|ax.r$]');

        ID NAME
---------- --------------------
         4 Alexender
         4 Alexendar

 

 

QQ:252803295

学习交流QQ群:
DSI&Core Search  Ⅰ 群:127149411(技术:已满)
DSI&Core Search  Ⅱ 群:177089463(技术:未满)
DSI&Core Search  Ⅲ 群:284596437(技术:未满)
DSI&Core Search  Ⅳ 群:192136702(技术:未满)
DSI&Core Search  Ⅴ 群:285030382(闲聊:未满)


MAIL:oracledba_cn@hotmail.com

BLOG: http://blog.csdn.net/guoyjoe

WEIBO:http://weibo.com/guoyJoe0218

ITPUB: http://www.itpub.net/space-uid-28460966.html

OCM:   http://education.oracle.com/education/otn/YGuo.HTM

抱歉!评论已关闭.