EsgynDB2.7版本中支持三种常用的正则函数,
根据正则表达式做字符串替换
REGEXP_REPLACE(instr,pattern,replace_str)
//将 01234 替换为 0abc
select regexp_replace('0123456789','01234','0abc') from dual;
SQL>select regexp_replace('0123456789','01234','0abc') from dual;
(EXPR)
--------------------
0abc56789
--- 1 row(s) selected.
将匹配到的数字替换为’ *#
select regexp_replace('01234abcde56789','[0-9]','*#') as new_str from dual;
SQL>select regexp_replace('01234abcde56789','[0-9]','*#') as new_str from dual;
NEW_STR
------------------------------
*#*#*#*#*#abcde*#*#*#*#*#
--- 1 row(s) selected.
//将字符串中的字母去掉(小写字母)
select regexp_replace('01234abcde56789','[a-z]','') as new_str from dual;
SQL>select regexp_replace('01234abcde56789','[a-z]','') as new_str from dual;
NEW_STR
------------------------------
0123456789
--- 1 row(s) selected.
//查询使用正则分割后的第一个值,也就是17
select regexp_substr('17,20,23','[^,]+',1,1) as str from dual;
SQL>select regexp_substr('17,20,23','[^,]+',1,1) as str from dual;
STR
--------
17
--- 1 row(s) selected.
//查询使用正则分割后的最后一个值,也就是23
select regexp_substr('17,20,23','[^,]+',1,3) as str from dual;
SQL>select regexp_substr('17,20,23','[^,]+',1,3) as str from dual;
STR
--------
23
--- 1 row(s) selected.
//获取一个多个数值的列,从而能够让结果以多行的形式展示出来
select nvl(regexp_substr('17,20,23', '[^,]+', 1, level), 'null') as str from dual connect by level <= 7;
SQL>select nvl(regexp_substr('17,20,23', '[^,]+', 1, level), 'null') as str from dual connect by level <= 7;
STR
--------
17
20
23
null
null
null
null
--- 7 row(s) selected.
//得到字符串中ge的出现次数
select regexp_count('george','ge',1) from dual;
SQL>select regexp_count('george','ge',1) from dual;
(EXPR)
----------
2
--- 1 row(s) selected.
//得到字符串中小写字母“a”的出现次数
select regexp_count ('The pro-niece was born today, so exciting.', 'a') "Count 'a'" from dual;
SQL>select regexp_count ('The pro-niece was born today, so exciting.', 'a') "Count 'a'" from dual;
Count 'a'
----------
2
--- 1 row(s) selected.
//从第17个字符处开始检索字母a
select regexp_count ('The pro-niece was born today, so exciting!', 'a', 17) "Count 'a'" from dual;
SQL>select regexp_count ('The pro-niece was born today, so exciting!', 'a', 17) "Count 'a'" from dual;
Count 'a'
----------
1
--- 1 row(s) selected.