在10g之前,要计算如下字符串:
SCKF100,CDKF200,MSKF300,ZYKF400,GYKF500
中‘KF’子字符串出现的次数,很困难。结合translate函数可以完成,但是很麻烦:
select length(translate(str1, 'KF' || str1, 'KF')) / length('KF')
from (select 'SCKF100,CDKF200,MSKF300,ZYKF400,GYKF500' as str1 from dual)
结果为5,表示'KF'出现5次。
但在10g中,可以利用regexp_count函数轻松完成:
select regexp_count(str1,'KF')
from (select 'SCKF100,CDKF200,MSKF300,ZYKF400,GYKF500' as str1 from dual)
挺方便的吧?!