oracle 统计某个字符出现的次数

1.情景展示

在oracle当中,如何统计某个字符/指定字符串在字符串中出现的次数?

如:411600,411602,411603,411606,411609,411621,411622,411623,411624,411625,411626,411627,411628,411643,411681。

2.具体分析

通过LENGTHB()+TRANSLATE()或者LENGTHB()+REPLACE()实现。

3.解决方案

方式一:LENGTHB(TRANSLATE(string, character || string, character))

SELECT LENGTHB(TRANSLATE('411600,411602,411603,411606,411609,411621,411622,411623,411624,411625,411626,411627,411628,411643,411681',
                         ',' ||
                         '411600,411602,411603,411606,411609,411621,411622,411623,411624,411625,411626,411627,411628,411643,411681',
                         ','))
  FROM DUAL

 

TRANSLATE(string, character || string, character):只保留某些特定字符,并将其余字符排除。

方式二:LENGTHB(string)-LENGTHB(REPLACE(string, character, ''))

SELECT LENGTHB('411600,411602,411603,411606,411609,411621,411622,411623,411624,411625,411626,411627,411628,411643,411681') -
       LENGTHB(REPLACE('411600,411602,411603,411606,411609,411621,411622,411623,411624,411625,411626,411627,411628,411643,411681,',
                       ',',
                       ''))
  FROM DUAL;

REPLACE(string, character, ''):将字符串当中的特定字符替换成空。

写在最后

  哪位大佬如若发现文章存在纰漏之处或需要补充更多内容,欢迎留言!!!

 相关推荐:

posted @ 2022-03-14 17:17  Marydon  阅读(5484)  评论(0编辑  收藏  举报