Oracle中REGEXP_SUBSTR函数的使用说明:
在oracle中,使用一条语句实现将'17,20,23'拆分成'17','20','23'的集合。
function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier)
__position :起始位置,从第几个字符开始正则表达式匹配(默认为1)
__occurrence :标识第几个匹配组,默认为1
__modifier :模式('i'不区分大小写进行检索;'c'区分大小写进行检索。默认为'c'。)
SELECT REGEXP_SUBSTR('17,20,23','[^,]+',1,1,'i') AS STR FROM DUAL;
SELECT REGEXP_SUBSTR('17,20,23','[^,]+',1,3,'i') AS STR FROM DUAL;
3、获取一个多个数值的列,从而能够让结果以多行的形式展示出来
SELECT LEVEL FROM DUAL CONNECT BY LEVEL
4、将上面REGEXP_SUBSTR的occurrence关联
SELECT NVL(REGEXP_SUBSTR('17,20,23', '[^,]+', 1, LEVEL, 'i'), 'NULL') AS STR
CONNECT BY LEVEL
5、优化上面的SQL语句,让生成的行的数量符合实际情况
SELECT REGEXP_SUBSTR('17,20,23', '[^,]+', 1, LEVEL, 'i') AS STR
CONNECT BY LEVEL
LENGTH('17,20,23') - LENGTH(REGEXP_REPLACE('17,20,23', ',', ''))+1;
阅读(6184) | 评论(0) | 转发(0) |