regexp_replace函数和regexp_substr函数:
regexp_replace函数和regexp_substr函数的功能类似与字符函数replace和substr,只是这里的应用更加灵活,可以一下子匹配一系列的结果,而原来的函数只能一下子匹配一个固定的字符换。
1.regexp_replace的意义是: 找到给定模式匹配的字符串并用其他的字符串来替代。
语法:
regexp_replace(x,pattern[,replace_string[,start[,occurence[match_option]]]])
每个参数的意思分别是:
x 待匹配的字符串
pattern 正则表达式元字符构成的匹配模式
replace_string 替换字符串
start 开始位置
occurence 匹配次数
match_option 匹配参数
举例如下:
select regexp_replace('hello everybody,may I have your attention please?',
'b[[:alpha:]]{3}',
'one')
from dual;
将会返回结果:
hello everyone,may I have your attention please?
2.regexp_substr函数的意义: 找出与给定模式匹配的字符串并返回,
语法:
regexp_substr(x,pattern[,start[,occurence[match_option]]])
//这里各参数的意义与前面的函数regexp_replace的含义是一样做的。
举例如下:
select regexp_substr('I love oracle very much', 'o[[:alpha:]]{5}')
from dual;
将会返回结果:
oracle