【oracle】统计字段里逗号的数量,采用函数regexp(field,',')

实验表:

create table tmp(
id int,
name nvarchar2(20),
primary key(id));

实验数据:

insert into tmp(id,name) values(1,'an,dy');
insert into tmp(id,name) values(2,'a,n,d,y');
insert into tmp(id,name) values(3,'andy,');
insert into tmp(id,name) values(4,',Bill');

函数使用:

SQL> select regexp_count(name,',') as ct,name from tmp;

        CT NAME
---------- ----------------------------------------
         1 an,dy
         3 a,n,d,y
         1 andy,
         1 ,Bill

核心:

select regexp_count(name,',') as ct,name from tmp;

--END--

原文地址:https://www.cnblogs.com/heyang78/p/15239427.html