REGEXP¶
说明¶
字符串的任意子串是否能匹配某正则达式
返回值¶
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');
--查询value子串中以1开头60结束的记录并且长度是7位并且全部是数字的记录。
select * from test_regexp where value regexp '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 value regexp '^[[:digit:]]+$' order by id;
ID(varchar) |VALUE(varchar) |
-------------------------------------
10 |abcbvbnb |
-------------------------------------
10 |1B |
-------------------------------------
3 |1b3b560 |
-------------------------------------
4 |abc |
-------------------------------------
5 |abcde |
-------------------------------------
6 |ADREasx |
-------------------------------------
7 |123 45 |
-------------------------------------
8 |adc de |
-------------------------------------
9 |adc,.de |
总数目:9
-- 删除表
DROP TABLE test_regexp;