match_option: 匹配方式选项。缺省为c。
c:case sensitive
I:case insensitive
n:(.)匹配任何字符(包括newline)
m:字符串存在换行的时候被作为多行处理
下面通过一些具体的例子来说明如何使用这四个函数。首先创建一个测试数据表,
Sql代码
SQL> create table person (
2 first_name varchar(20),
3 last_name varchar(20),
4 email varchar(100),
5 zip varchar(6));
Table created.
SQL> insert into person values ('Steven', 'Chen', 'steven@hp.com', '123456');
1 row created.
SQL> insert into person values ('James', 'Li', 'jamesli@sun.com' || chr(10) || 'lijames@oracle.com', '1b3d5f');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from person;
FIRST_NAME LAST_NAME EMAIL ZIP
---------- ---------- -------------------- ------
Steven Chen steven@hp.com 123456
James Li jamesli@sun.com 1b3d5f
lijames@oracle.com
1。REGEXP_LIKE
Sql代码
SQL> select zip as invalid_zip from person where regexp_like(zip, '[^[:digit:]]');
INVALID_ZIP
--------------------
1b3d5f
SQL> select first_name from person where regexp_like(first_name, '^S.*n$');
FIRST_NAME
----------
Steven
SQL> select first_name from person where regexp_like(first_name, '^s.*n$');
no rows selected
SQL> select first_name from person where regexp_like(first_name, '^s.*n$', 'c');
no rows selected
SQL> select first_name from person where regexp_like(first_name, '^s.*n$', 'i');
FIRST_NAME
----------
Steven
SQL> select email from person where regexp_like(email, '^james.*com$');
no rows selected
SQL> select email from person where regexp_like(email, '^james.*com$', 'n');
--------------------
jamesli@sun.com
lijames@oracle.com
SQL> select email from person where regexp_like(email, '^li.*com$');
no rows selected
SQL> select email from person where regexp_like(email, '^li.*com$', 'm');
--------------------
jamesli@sun.com
lijames@oracle.com
2。REGEXP_INSTR
Sql代码
查找zip中第一个非数字字符的位置
SQL> select regexp_instr(zip, '[^[:digit:]]') as position from person;
POSITION
----------
0
2
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|