REGEXP_LIKE

说明

字符串的任意子串是否能匹配某正则达式

语法

regexp_like ::=

参数

source_char

源字符串 字符类型

pattern

正则表达式

match_param

指定匹配参数

i:大小写不敏感;

c:大小写敏感;

n:点号 . 不匹配换行符号;

m:多行模式;

x:扩展模式,忽略正则表达式中的空白字符;

u: 使用unicode字符集。

返回值

BOOL 类型 TRUE 符合;FALSE 不符合

示例

根据正则表达式查找

--  清理环境
DROP TABLE test_regexp CASCADE;

--创建表
create table test_regexp
(
  id varchar(4),
  value varchar(10)
);
--数据插入
insert into test_regexp values('1','1234560');
insert into test_regexp values('2','1234560');
insert into test_regexp values('3','1b3b560');
insert into test_regexp values('4','abc');
insert into test_regexp values('5','abcde');
insert into test_regexp values('6','ADREasx');
insert into test_regexp values('7','123  45');
insert into test_regexp values('8','adc  de');
insert into test_regexp values('9','adc,.de');
insert into test_regexp values('10','1B');
insert into test_regexp values('10','abcbvbnb');
insert into test_regexp values('11','11114560');
insert into test_regexp values('11','11124560');
insert into test_regexp values('12',convert_encoding_using('你好世界', 'utf8'));

--查询value子串中以1开头60结束的记录并且长度是7位并且全部是数字的记录。
select * from test_regexp where regexp_like(value,'1[0-9]{4}60') order by id;
ID(varchar)      |VALUE(varchar)      |
-------------------------------------
1                |1234560             |
-------------------------------------
11               |11114560            |
-------------------------------------
11               |11124560            |
-------------------------------------
2                |1234560             |
总数目:4

-- 查询value子串中不是纯数字的记录。
select * from test_regexp where not regexp_like(value,'^[[:digit:]]+$') order by id;
ID(varchar)      |VALUE(varchar)      |
-------------------------------------
10               |abcbvbnb            |
-------------------------------------
10               |1B                  |
-------------------------------------
12               |你好世界                |
-------------------------------------
3                |1b3b560             |
-------------------------------------
4                |abc                 |
-------------------------------------
5                |abcde               |
-------------------------------------
6                |ADREasx             |
-------------------------------------
7                |123  45             |
-------------------------------------
8                |adc  de             |
-------------------------------------
9                |adc,.de             |
总数目:10

--查询value子串中以12或者1b开头的记录.不区分大小写。
select * from test_regexp where regexp_like(value,'^1[2b]','i') order by id;
ID(varchar)      |VALUE(varchar)      |
-------------------------------------
1                |1234560             |
-------------------------------------
10               |1B                  |
-------------------------------------
2                |1234560             |
-------------------------------------
3                |1b3b560             |
-------------------------------------
7                |123  45             |
总数目:5

--查询value子串中以 utf8 编码保存的中文记录。
select * from test_regexp where regexp_like(value,'[\x{4e00}-\x{9fa5}]+','u') order by id;
ID(varchar)      |VALUE(varchar)      |
-------------------------------------
12               |你好世界                |
总数目:1
--  删除表
DROP TABLE test_regexp;