문자열에서 특정 문자 개수 구하기

문자열 중에서 특정 문자가 몇 개 있는지 확인 하는 쿼리
with table_a as (
    select 'aaa' user_id, '000023333033333333333333333333333333' study from dual union all
    select 'bbb' user_id, '0113333233' study from dual union all
    select 'ccc' user_id, '333331333333333333330332333333333303' study from dual union all
    select 'ddd' user_id, '333333333333333333333333333333333313' study from dual union all
    select 'eee' user_id, '1313333333' study from dual union all
    select 'fff' user_id, '0333333333' study from dual union all
    select 'ggg' user_id, '323333333' study from dual union all
    select 'hhh' user_id, '0002001333' from dual    
)
select user_id
     , regexp_count(study, '0') s0
     , regexp_count(study, '1') s1
     , regexp_count(study, '2') s2
     , regexp_count(study, '3') s3               
  from table_a  
;

USE         S0         S1         S2         S3
--- ---------- ---------- ---------- ----------
aaa          5          0          1         30
bbb          1          2          1          6
ccc          2          1          1         32
ddd          0          1          0         35
eee          0          2          0          8
fff          1          0          0          9
ggg          0          0          1          8
hhh          5          1          1          3

You may also like...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다